Skip to content

Commit 97c52db

Browse files
committed
added ecsnodeclass validation cel
1 parent af87ebd commit 97c52db

File tree

346 files changed

+214405
-497
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

346 files changed

+214405
-497
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ run: ## Run Karpenter controller binary against your local cluster
4242
update: tidy download ## Update go files header, CRD and generated code
4343
hack/boilerplate.sh
4444
hack/update-generated.sh
45+
hack/validation/kubelet.sh
4546

4647
verify: ## Verify code. Includes linting, formatting, etc
4748
golangci-lint run

config/components/crds/karpenter.k8s.alicloud_ecsnodeclasses.yaml

Lines changed: 456 additions & 487 deletions
Large diffs are not rendered by default.

config/config.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Copyright 2024 The CloudPilot AI Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package config
18+
19+
import _ "embed"
20+
21+
//go:embed components/crds/karpenter.k8s.alicloud_ecsnodeclasses.yaml
22+
var ECSNodeClassCRD []byte

go.mod

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ require (
1313
github.com/awslabs/operatorpkg v0.0.0-20240805231134-67d0acfb6306
1414
github.com/cloudpilot-ai/priceserver v0.0.0-20241011010411-15ac0e19a857
1515
github.com/mitchellh/hashstructure/v2 v2.0.2
16+
github.com/onsi/ginkgo/v2 v2.20.0
17+
github.com/onsi/gomega v1.34.1
1618
github.com/patrickmn/go-cache v2.1.0+incompatible
1719
github.com/samber/lo v1.47.0
1820
github.com/stretchr/testify v1.9.0
@@ -27,8 +29,12 @@ require (
2729
)
2830

2931
require (
32+
github.com/Pallinder/go-randomdata v1.2.0 // indirect
33+
github.com/avast/retry-go v3.0.0+incompatible // indirect
3034
github.com/evanphx/json-patch v5.7.0+incompatible // indirect
31-
github.com/onsi/ginkgo/v2 v2.20.0 // indirect
35+
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
36+
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8 // indirect
37+
golang.org/x/tools v0.24.0 // indirect
3238
google.golang.org/genproto v0.0.0-20231009173412-8bfb1ae86b6c // indirect
3339
)
3440

@@ -68,7 +74,7 @@ require (
6874
github.com/google/uuid v1.6.0 // indirect
6975
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect
7076
github.com/hashicorp/golang-lru v1.0.2 // indirect
71-
github.com/imdario/mergo v0.3.16 // indirect
77+
github.com/imdario/mergo v0.3.16
7278
github.com/inconshreveable/mousetrap v1.1.0 // indirect
7379
github.com/josharian/intern v1.0.0 // indirect
7480
github.com/json-iterator/go v1.1.12 // indirect
@@ -110,7 +116,7 @@ require (
110116
gopkg.in/ini.v1 v1.67.0 // indirect
111117
gopkg.in/yaml.v2 v2.4.0 // indirect
112118
gopkg.in/yaml.v3 v3.0.1 // indirect
113-
k8s.io/apiextensions-apiserver v0.30.3 // indirect
119+
k8s.io/apiextensions-apiserver v0.30.3
114120
k8s.io/cloud-provider v0.30.3 // indirect
115121
k8s.io/component-base v0.30.3 // indirect
116122
k8s.io/csi-translation-lib v0.30.3 // indirect

go.sum

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+
174174
github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU=
175175
github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
176176
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
177-
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
178177
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
179178
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
180179
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
@@ -469,8 +468,8 @@ golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
469468
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
470469
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
471470
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
472-
golang.org/x/mod v0.19.0 h1:fEdghXQSo20giMthA7cd28ZC+jts4amQ3YMXiP5oMQ8=
473-
golang.org/x/mod v0.19.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
471+
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
472+
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
474473
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
475474
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
476475
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=

hack/validation/kubelet.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Kubelet Validation
2+
3+
# The regular expression adds validation for kubelet.kubeReserved and kubelet.systemReserved values of the map are resource.Quantity
4+
# Quantity: https://github.com/kubernetes/apimachinery/blob/d82afe1e363acae0e8c0953b1bc230d65fdb50e2/pkg/api/resource/quantity.go#L100
5+
# EC2NodeClass Validation:
6+
yq eval '.spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.kubeletConfiguration.properties.kubeReserved.additionalProperties.pattern = "^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$"' -i config/components/crds/karpenter.k8s.alicloud_ecsnodeclasses.yaml
7+
yq eval '.spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.kubeletConfiguration.properties.systemReserved.additionalProperties.pattern = "^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$"' -i config/components/crds/karpenter.k8s.alicloud_ecsnodeclasses.yaml
8+
9+
# The regular expression is a validation for kubelet.evictionHard and kubelet.evictionSoft are percentage or a resource.Quantity
10+
# Quantity: https://github.com/kubernetes/apimachinery/blob/d82afe1e363acae0e8c0953b1bc230d65fdb50e2/pkg/api/resource/quantity.go#L100
11+
# EC2NodeClass Validation:
12+
yq eval '.spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.kubeletConfiguration.properties.evictionHard.additionalProperties.pattern = "^((\d{1,2}(\.\d{1,2})?|100(\.0{1,2})?)%||(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?)$"' -i config/components/crds/karpenter.k8s.alicloud_ecsnodeclasses.yaml
13+
yq eval '.spec.versions[0].schema.openAPIV3Schema.properties.spec.properties.kubeletConfiguration.properties.evictionSoft.additionalProperties.pattern = "^((\d{1,2}(\.\d{1,2})?|100(\.0{1,2})?)%||(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?)$"' -i config/components/crds/karpenter.k8s.alicloud_ecsnodeclasses.yaml

pkg/apis/apis.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ limitations under the License.
1818
package apis
1919

2020
import (
21+
"github.com/awslabs/operatorpkg/object"
22+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2123
"sigs.k8s.io/karpenter/pkg/apis"
24+
25+
"github.com/cloudpilot-ai/karpenter-provider-alicloud/config"
2226
)
2327

2428
var (
2529
Group = "karpenter.k8s.alicloud"
2630
CompatibilityGroup = "compatibility." + Group
27-
CRDs = apis.CRDs // object.Unmarshal[apiextensionsv1.CustomResourceDefinition](crds.ECSNodeClassCRD)
31+
CRDs = append(apis.CRDs, object.Unmarshal[apiextensionsv1.CustomResourceDefinition](config.ECSNodeClassCRD))
2832
)

0 commit comments

Comments
 (0)