From 0fe936dd55c9c3db0ccbd1d541f59bcb207e4912 Mon Sep 17 00:00:00 2001 From: Jimmi Dyson Date: Thu, 18 Apr 2024 14:32:40 +0100 Subject: [PATCH 1/6] refactor: Use separate types for provider cluster configs This commit also switches to using controller-gen generated CRDs for the OpenAPI schema for the variable definitions. A lot of this commit is refactoring tests. --- api/go.mod | 29 ++ api/go.sum | 60 ++- api/v1alpha1/addon_types.go | 235 ----------- api/v1alpha1/aws_clusterconfig_types.go | 99 ----- api/v1alpha1/clusterconfig_types.go | 386 +++++------------- api/v1alpha1/common_types.go | 27 -- .../caren.nutanix.com_awsclusterconfigs.yaml | 372 +++++++++++++++++ .../caren.nutanix.com_awsnodeconfigs.yaml | 89 ++++ ...aren.nutanix.com_dockerclusterconfigs.yaml | 297 ++++++++++++++ .../caren.nutanix.com_dockernodeconfigs.yaml | 52 +++ ...ren.nutanix.com_genericclusterconfigs.yaml | 285 +++++++++++++ ...en.nutanix.com_nutanixclusterconfigs.yaml} | 107 +---- ...caren.nutanix.com_nutanixnodeconfigs.yaml} | 61 +-- api/v1alpha1/docker_node_types.go | 12 - api/v1alpha1/node_types.go | 86 ---- api/v1alpha1/nodeconfig_types.go | 97 +++++ api/v1alpha1/nutanix_clusterconfig_types.go | 60 --- api/v1alpha1/nutanix_node_types.go | 156 +------ api/v1alpha1/zz_generated.deepcopy.go | 344 +++++++++++++--- .../clustertopology/variables/fromcrdyaml.go | 161 ++++++++ common/pkg/testutils/openapi/convert.go | 10 +- common/pkg/testutils/openapi/validate.go | 2 +- go.mod | 2 +- pkg/common/clusterconfig/types.go | 16 + pkg/handlers/aws/clusterconfig/variables.go | 2 +- .../aws/mutation/ami/variables_test.go | 6 +- .../variables_test.go | 8 +- .../iaminstanceprofile/variables_test.go | 6 +- .../mutation/instancetype/variables_test.go | 6 +- .../aws/mutation/network/variables_test.go | 8 +- .../aws/mutation/region/variables_test.go | 4 +- .../mutation/securitygroups/variables_test.go | 6 +- pkg/handlers/aws/workerconfig/variables.go | 2 +- .../aws/workerconfig/variables_test.go | 6 +- .../docker/clusterconfig/variables.go | 2 +- .../mutation/customimage/variables_test.go | 10 +- pkg/handlers/docker/workerconfig/variables.go | 2 +- .../docker/workerconfig/variables_test.go | 2 +- .../generic/clusterconfig/variables_test.go | 2 +- .../generic/lifecycle/ccm/aws/handler.go | 4 +- pkg/handlers/generic/lifecycle/ccm/handler.go | 5 +- .../generic/lifecycle/ccm/nutanix/handler.go | 6 +- .../lifecycle/ccm/nutanix/handler_test.go | 16 +- .../clusterautoscaler/variables_test.go | 6 +- .../generic/lifecycle/cni/variables_test.go | 8 +- .../generic/lifecycle/nfd/variables_test.go | 6 +- .../generic/mutation/etcd/variables_test.go | 8 +- .../extraapiservercertsans/inject_test.go | 20 +- .../extraapiservercertsans/variables_test.go | 6 +- .../mutation/httpproxy/variables_test.go | 2 +- .../credentials/variables_test.go | 10 +- .../variables_test.go | 2 +- .../mutation/mirrors/variables_test.go | 8 +- .../generic/mutation/users/variables_test.go | 2 +- .../generic/workerconfig/variables.go | 42 -- .../generic/workerconfig/variables_test.go | 23 -- .../nutanix/clusterconfig/variables.go | 2 +- .../controlplaneendpoint/variables_test.go | 8 +- .../mutation/machinedetails/variables_test.go | 8 +- .../prismcentralendpoint/variables_test.go | 16 +- .../nutanix/workerconfig/variables.go | 2 +- .../nutanix/workerconfig/variables_test.go | 2 +- 62 files changed, 1967 insertions(+), 1362 deletions(-) create mode 100644 api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml create mode 100644 api/v1alpha1/crds/caren.nutanix.com_awsnodeconfigs.yaml create mode 100644 api/v1alpha1/crds/caren.nutanix.com_dockerclusterconfigs.yaml create mode 100644 api/v1alpha1/crds/caren.nutanix.com_dockernodeconfigs.yaml create mode 100644 api/v1alpha1/crds/caren.nutanix.com_genericclusterconfigs.yaml rename api/v1alpha1/crds/{caren.nutanix.com_clusterconfigs.yaml => caren.nutanix.com_nutanixclusterconfigs.yaml} (84%) rename api/v1alpha1/crds/{caren.nutanix.com_nodeconfigs.yaml => caren.nutanix.com_nutanixnodeconfigs.yaml} (79%) delete mode 100644 api/v1alpha1/node_types.go create mode 100644 api/v1alpha1/nodeconfig_types.go create mode 100644 common/pkg/capi/clustertopology/variables/fromcrdyaml.go create mode 100644 pkg/common/clusterconfig/types.go delete mode 100644 pkg/handlers/generic/workerconfig/variables_test.go diff --git a/api/go.mod b/api/go.mod index b781b7867..befb33a07 100644 --- a/api/go.mod +++ b/api/go.mod @@ -7,7 +7,10 @@ go 1.21 toolchain go1.22.2 +replace github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common => ../common + require ( + github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common v0.7.0 github.com/nutanix-cloud-native/prism-go-client v0.3.4 github.com/onsi/gomega v1.33.0 k8s.io/api v0.29.3 @@ -19,31 +22,57 @@ require ( ) require ( + github.com/beorn7/perks v1.0.1 // indirect github.com/blang/semver/v4 v4.0.0 // indirect + github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect + github.com/evanphx/json-patch/v5 v5.9.0 // indirect + github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logr/logr v1.4.1 // indirect github.com/go-openapi/jsonpointer v0.19.6 // indirect github.com/go-openapi/jsonreference v0.20.2 // indirect github.com/go-openapi/swag v0.22.3 // indirect github.com/gogo/protobuf v1.3.2 // indirect + github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/google/gnostic-models v0.6.8 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/google/gofuzz v1.2.0 // indirect + github.com/google/uuid v1.3.1 // indirect + github.com/imdario/mergo v0.3.13 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/mailru/easyjson v0.7.7 // indirect + github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/pkg/errors v0.9.1 // indirect + github.com/prometheus/client_golang v1.18.0 // indirect + github.com/prometheus/client_model v0.5.0 // indirect + github.com/prometheus/common v0.45.0 // indirect + github.com/prometheus/procfs v0.12.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect + github.com/valyala/fastjson v1.6.4 // indirect + golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect golang.org/x/net v0.24.0 // indirect + golang.org/x/oauth2 v0.14.0 // indirect + golang.org/x/sys v0.19.0 // indirect + golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect + golang.org/x/time v0.3.0 // indirect + gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect + google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.33.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect + k8s.io/client-go v0.29.3 // indirect + k8s.io/component-base v0.29.3 // indirect k8s.io/klog/v2 v2.120.1 // indirect k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect + sigs.k8s.io/yaml v1.4.0 // indirect ) diff --git a/api/go.sum b/api/go.sum index 81d5fd288..c42d5ad3f 100644 --- a/api/go.sum +++ b/api/go.sum @@ -62,12 +62,16 @@ github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkY github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= github.com/aws/aws-sdk-go v1.42.23/go.mod h1:gyRszuZ/icHmHAVE4gc/r+cfCmhA1AD+vqfWbgI+eHs= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= +github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= +github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= github.com/bnkamalesh/webgo/v4 v4.1.11/go.mod h1:taIAonQTzao8G5rnB22WgKmQuIOWHpQ0n/YLAidBXlM= github.com/bnkamalesh/webgo/v6 v6.2.2/go.mod h1:2Y+dEdTp1xC/ra+3PAVZV6hh4sCI+iPK7mcHt+t9bfM= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= @@ -104,10 +108,16 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= +github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U= +github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= +github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg= +github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ= github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= github.com/form3tech-oss/jwt-go v3.2.3+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= +github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= +github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/getkin/kin-openapi v0.76.0/go.mod h1:660oXbgy5JFMKreazJaQTw7o+X00qeSyhcnluiMv+Xg= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= @@ -126,6 +136,8 @@ github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/zapr v1.2.3/go.mod h1:eIauM6P8qSvTw5o2ez6UEAfGjQKrxQTl5EoK+Qa2oG4= +github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ= +github.com/go-logr/zapr v1.3.0/go.mod h1:YKepepNBd1u/oyhd/yQmtjVXmm9uML4IXUgMOwR8/Gg= github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE= @@ -150,6 +162,8 @@ github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg78 github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= +github.com/gobuffalo/flect v1.0.2 h1:eqjPGSo2WmjgY2XlpGwo2NXgL3RucAKo4k4qQMNA5sA= +github.com/gobuffalo/flect v1.0.2/go.mod h1:A5msMlrHtLqh9umBSnvabjsMrCcCpAyzglnDvkbYKHs= github.com/goccy/go-json v0.9.4/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= @@ -158,6 +172,7 @@ github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfU github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= @@ -232,6 +247,8 @@ github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLe github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= +github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= @@ -245,6 +262,8 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= +github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= +github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= @@ -297,6 +316,8 @@ github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= +github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg= +github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k= github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= github.com/mitchellh/mapstructure v1.2.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/moby/spdystream v0.2.0/go.mod h1:f7i0iNDQJ059oMTcWxx8MA/zKFIuD/lY+0GqbN2Wy8c= @@ -309,6 +330,7 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= @@ -341,7 +363,15 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk= +github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= +github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw= +github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI= +github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lneoxM= +github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY= +github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo= +github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= @@ -368,14 +398,16 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.35.0/go.mod h1:t/G+3rLek+CyY9bnIE+YlMRddxVAAGjhxndDB4i4C0I= +github.com/valyala/fastjson v1.6.4 h1:uAUNq9Z6ymTgGhcm0UynUAB6tlbakBrz6CQFax3BXVQ= +github.com/valyala/fastjson v1.6.4/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY= github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= @@ -405,10 +437,16 @@ go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.1.11/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= +go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= +go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= go.uber.org/zap v1.19.1/go.mod h1:j3DNczoxDZroyBnOT1L/Q79cfUMGZxlv/9dzN7SM1rI= go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw= +go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= +go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -432,6 +470,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g= +golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -515,6 +555,8 @@ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= +golang.org/x/oauth2 v0.14.0 h1:P0Vrf/2538nmC0H+pEQ3MNFRRnVR7RlqyVw+bvm26z0= +golang.org/x/oauth2 v0.14.0/go.mod h1:lAtNWgaWfL4cm7j2OV8TxGi9Qb7ECORx8DktCY74OwM= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -588,6 +630,8 @@ golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= +golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -604,6 +648,8 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxb golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20220210224613-90d013bbcef8/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= +golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190125232054-d66bd3c5d5a6/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -666,6 +712,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw= +gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= @@ -693,6 +741,7 @@ google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= @@ -793,6 +842,7 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= @@ -812,6 +862,12 @@ k8s.io/apimachinery v0.24.3/go.mod h1:82Bi4sCzVBdpYjyI4jY6aHX+YCUchUIrZrXKedjd2U k8s.io/apimachinery v0.29.3 h1:2tbx+5L7RNvqJjn7RIuIKu9XTsIZ9Z5wX2G22XAa5EU= k8s.io/apimachinery v0.29.3/go.mod h1:hx/S4V2PNW4OMg3WizRrHutyB5la0iCUbZym+W0EQIU= k8s.io/client-go v0.24.2/go.mod h1:zg4Xaoo+umDsfCWr4fCnmLEtQXyCNXCvJuSsglNcV30= +k8s.io/client-go v0.29.3 h1:R/zaZbEAxqComZ9FHeQwOh3Y1ZUs7FaHKZdQtIc2WZg= +k8s.io/client-go v0.29.3/go.mod h1:tkDisCvgPfiRpxGnOORfkljmS+UrW+WtXAy2fTvXJB0= +k8s.io/cluster-bootstrap v0.29.3 h1:DIMDZSN8gbFMy9CS2mAS2Iqq/fIUG783WN/1lqi5TF8= +k8s.io/cluster-bootstrap v0.29.3/go.mod h1:aPAg1VtXx3uRrx5qU2jTzR7p1rf18zLXWS+pGhiqPto= +k8s.io/component-base v0.29.3 h1:Oq9/nddUxlnrCuuR2K/jp6aflVvc0uDvxMzAWxnGzAo= +k8s.io/component-base v0.29.3/go.mod h1:Yuj33XXjuOk2BAaHsIGHhCKZQAgYKhqIxIjIr2UXYio= k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E= k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y= diff --git a/api/v1alpha1/addon_types.go b/api/v1alpha1/addon_types.go index 6a74b5645..5987ebd89 100644 --- a/api/v1alpha1/addon_types.go +++ b/api/v1alpha1/addon_types.go @@ -6,10 +6,6 @@ package v1alpha1 import ( corev1 "k8s.io/api/core/v1" storagev1 "k8s.io/api/storage/v1" - "k8s.io/utils/ptr" - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/variables" ) const ( @@ -40,22 +36,6 @@ type Addons struct { CSIProviders *CSI `json:"csi,omitempty"` } -func (Addons) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "Cluster configuration", - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "cni": CNI{}.VariableSchema().OpenAPIV3Schema, - "nfd": NFD{}.VariableSchema().OpenAPIV3Schema, - "clusterAutoscaler": ClusterAutoscaler{}.VariableSchema().OpenAPIV3Schema, - "csi": CSI{}.VariableSchema().OpenAPIV3Schema, - "ccm": CCM{}.VariableSchema().OpenAPIV3Schema, - }, - }, - } -} - type AddonStrategy string // CNI required for providing CNI configuration. @@ -66,83 +46,18 @@ type CNI struct { Strategy AddonStrategy `json:"strategy,omitempty"` } -func (CNI) VariableSchema() clusterv1.VariableSchema { - supportedCNIProviders := []string{CNIProviderCalico, CNIProviderCilium} - - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "provider": { - Description: "CNI provider to deploy", - Type: "string", - Enum: variables.MustMarshalValuesToEnumJSON(supportedCNIProviders...), - }, - "strategy": { - Description: "Addon strategy used to deploy the CNI provider to the workload cluster", - Type: "string", - Enum: variables.MustMarshalValuesToEnumJSON( - AddonStrategyClusterResourceSet, - AddonStrategyHelmAddon, - ), - }, - }, - Required: []string{"provider", "strategy"}, - }, - } -} - // NFD tells us to enable or disable the node feature discovery addon. type NFD struct { // +optional Strategy AddonStrategy `json:"strategy,omitempty"` } -func (NFD) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "strategy": { - Description: "Addon strategy used to deploy Node Feature Discovery (NFD) to the workload cluster", - Type: "string", - Enum: variables.MustMarshalValuesToEnumJSON( - AddonStrategyClusterResourceSet, - AddonStrategyHelmAddon, - ), - }, - }, - Required: []string{"strategy"}, - }, - } -} - // ClusterAutoscaler tells us to enable or disable the cluster-autoscaler addon. type ClusterAutoscaler struct { // +optional Strategy AddonStrategy `json:"strategy,omitempty"` } -func (ClusterAutoscaler) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "strategy": { - Description: "Addon strategy used to deploy cluster-autoscaler to the management cluster," + - "targeting the workload cluster.", - Type: "string", - Enum: variables.MustMarshalValuesToEnumJSON( - AddonStrategyClusterResourceSet, - AddonStrategyHelmAddon, - ), - }, - }, - Required: []string{"strategy"}, - }, - } -} - type DefaultStorage struct { ProviderName string `json:"providerName"` StorageClassConfigName string `json:"storageClassConfigName"` @@ -183,159 +98,9 @@ type StorageClassConfig struct { AllowExpansion bool `json:"allowExpansion,omitempty"` } -func (StorageClassConfig) VariableSchema() clusterv1.VariableSchema { - supportedReclaimPolicies := []string{ - string(VolumeReclaimRecycle), - string(VolumeReclaimDelete), - string(VolumeReclaimRetain), - } - supportedBindingModes := []string{ - string(VolumeBindingImmediate), - string(VolumeBindingWaitForFirstConsumer), - } - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "object", - Required: []string{"name"}, - Properties: map[string]clusterv1.JSONSchemaProps{ - "name": { - Type: "string", - Description: "Name of storage class config.", - }, - "parameters": { - Type: "object", - Description: "Parameters passed into the storage class object.", - AdditionalProperties: &clusterv1.JSONSchemaProps{ - Type: "string", - }, - }, - "reclaimPolicy": { - Type: "string", - Enum: variables.MustMarshalValuesToEnumJSON(supportedReclaimPolicies...), - Default: variables.MustMarshal(VolumeReclaimDelete), - }, - "volumeBindingMode": { - Type: "string", - Enum: variables.MustMarshalValuesToEnumJSON(supportedBindingModes...), - Default: variables.MustMarshal(VolumeBindingWaitForFirstConsumer), - }, - "allowExpansion": { - Type: "boolean", - Default: variables.MustMarshal(false), - Description: "If the storage class should allow volume expanding", - }, - }, - }, - } -} - -func (CSIProvider) VariableSchema() clusterv1.VariableSchema { - supportedCSIProviders := []string{CSIProviderAWSEBS, CSIProviderNutanix} - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "object", - Required: []string{"name", "strategy"}, - Properties: map[string]clusterv1.JSONSchemaProps{ - "name": { - Description: "Name of the CSI Provider", - Type: "string", - Enum: variables.MustMarshalValuesToEnumJSON( - supportedCSIProviders...), - }, - "strategy": { - Description: "Addon strategy used to deploy the CSI provider to the workload cluster", - Type: "string", - Enum: variables.MustMarshalValuesToEnumJSON( - AddonStrategyClusterResourceSet, - AddonStrategyHelmAddon, - ), - }, - "credentials": { - Type: "object", - Description: "The reference to any secret used by the CSI Provider.", - Properties: map[string]clusterv1.JSONSchemaProps{ - "name": { - Type: "string", - }, - }, - }, - "storageClassConfig": { - Type: "array", - Items: ptr.To(StorageClassConfig{}.VariableSchema().OpenAPIV3Schema), - }, - }, - }, - } -} - -func (DefaultStorage) VariableSchema() clusterv1.VariableSchema { - supportedCSIProviders := []string{CSIProviderAWSEBS, CSIProviderNutanix} - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "object", - Description: "A tuple of provider name and storage class ", - Required: []string{"providerName", "storageClassConfigName"}, - Properties: map[string]clusterv1.JSONSchemaProps{ - "providerName": { - Type: "string", - Description: "Name of the CSI Provider for the default storage class", - Enum: variables.MustMarshalValuesToEnumJSON( - supportedCSIProviders..., - ), - }, - "storageClassConfigName": { - Type: "string", - Description: "Name of storage class config in any of the provider objects", - }, - }, - }, - } -} - -func (CSI) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "providers": { - Type: "array", - Items: ptr.To(CSIProvider{}.VariableSchema().OpenAPIV3Schema), - }, - "defaultStorage": DefaultStorage{}.VariableSchema().OpenAPIV3Schema, - }, - }, - } -} - // CCM tells us to enable or disable the cloud provider interface. type CCM struct { // A reference to the Secret for credential information for the target Prism Central instance // +optional Credentials *corev1.LocalObjectReference `json:"credentials,omitempty"` } - -func (CCM) VariableSchema() clusterv1.VariableSchema { - // TODO Validate credentials is set. - // This CCM is shared across all providers. - // Some of these providers may require credentials to be set, but we don't want to require it for all providers. - // The Nutanix CCM handler will fail in at runtime if credentials are not set. - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "credentials": { - Description: "A reference to the Secret for credential information" + - "for the target Prism Central instance", - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "name": { - Description: "The name of the Secret", - Type: "string", - }, - }, - Required: []string{"name"}, - }, - }, - }, - } -} diff --git a/api/v1alpha1/aws_clusterconfig_types.go b/api/v1alpha1/aws_clusterconfig_types.go index cfce84640..397242222 100644 --- a/api/v1alpha1/aws_clusterconfig_types.go +++ b/api/v1alpha1/aws_clusterconfig_types.go @@ -4,10 +4,7 @@ package v1alpha1 import ( - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - capav1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-provider-aws/v2/api/v1beta2" - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/variables" ) type AWSSpec struct { @@ -20,31 +17,8 @@ type AWSSpec struct { ControlPlaneLoadBalancer *AWSLoadBalancerSpec `json:"controlPlaneLoadBalancer,omitempty"` } -func (AWSSpec) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "AWS cluster configuration", - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "region": Region("").VariableSchema().OpenAPIV3Schema, - "network": AWSNetwork{}.VariableSchema().OpenAPIV3Schema, - "controlPlaneLoadBalancer": AWSLoadBalancerSpec{}.VariableSchema().OpenAPIV3Schema, - }, - }, - } -} - type Region string -func (Region) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "AWS region to create cluster in", - Type: "string", - }, - } -} - type AWSNetwork struct { // +optional VPC *VPC `json:"vpc,omitempty"` @@ -53,74 +27,19 @@ type AWSNetwork struct { Subnets Subnets `json:"subnets,omitempty"` } -func (AWSNetwork) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "AWS network configuration", - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "vpc": VPC{}.VariableSchema().OpenAPIV3Schema, - "subnets": Subnets{}.VariableSchema().OpenAPIV3Schema, - }, - }, - } -} - type VPC struct { // ID is the vpc-id of the VPC this provider should use to create resources. ID string `json:"id,omitempty"` } -func (VPC) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "AWS VPC configuration", - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "id": { - Description: "Existing VPC ID to use for the cluster", - Type: "string", - }, - }, - }, - } -} - type Subnets []SubnetSpec -func (Subnets) VariableSchema() clusterv1.VariableSchema { - resourceSchema := SubnetSpec{}.VariableSchema().OpenAPIV3Schema - - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "AWS Subnet configurations", - Type: "array", - Items: &resourceSchema, - }, - } -} - // SubnetSpec configures an AWS Subnet. type SubnetSpec struct { // ID defines a unique identifier to reference this resource. ID string `json:"id"` } -func (SubnetSpec) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "An AWS Subnet configuration", - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "id": { - Description: "Existing Subnet ID to use for the cluster", - Type: "string", - }, - }, - }, - } -} - // AWSLoadBalancerSpec configures an AWS control-plane LoadBalancer. type AWSLoadBalancerSpec struct { // Scheme sets the scheme of the load balancer (defaults to internet-facing) @@ -129,21 +48,3 @@ type AWSLoadBalancerSpec struct { // +optional Scheme *capav1.ELBScheme `json:"scheme,omitempty"` } - -func (AWSLoadBalancerSpec) VariableSchema() clusterv1.VariableSchema { - supportedScheme := []capav1.ELBScheme{capav1.ELBSchemeInternetFacing, capav1.ELBSchemeInternal} - - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "AWS control-plane LoadBalancer configuration", - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "scheme": { - Description: "Scheme sets the scheme of the load balancer (defaults to internet-facing)", - Type: "string", - Enum: variables.MustMarshalValuesToEnumJSON(supportedScheme...), - }, - }, - }, - } -} diff --git a/api/v1alpha1/clusterconfig_types.go b/api/v1alpha1/clusterconfig_types.go index 3e238f2b2..5f6ff4b14 100644 --- a/api/v1alpha1/clusterconfig_types.go +++ b/api/v1alpha1/clusterconfig_types.go @@ -4,16 +4,13 @@ package v1alpha1 import ( - "fmt" - "maps" - "strings" + _ "embed" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/openapi/patterns" + "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables" ) type StorageProvisioner string @@ -44,81 +41,125 @@ var ( "127.0.0.1", "0.0.0.0", } + + //go:embed crds/caren.nutanix.com_genericclusterconfigs.yaml + genericClusterConfigCRDDefinition []byte + //go:embed crds/caren.nutanix.com_dockerclusterconfigs.yaml + dockerClusterConfigCRDDefinition []byte + //go:embed crds/caren.nutanix.com_awsclusterconfigs.yaml + awsClusterConfigCRDDefinition []byte + //go:embed crds/caren.nutanix.com_nutanixclusterconfigs.yaml + nutanixClusterConfigCRDDefinition []byte + + genericClusterConfigVariableSchema = variables.MustSchemaFromCRDYAML( + genericClusterConfigCRDDefinition, + ) + dockerClusterConfigVariableSchema = variables.MustSchemaFromCRDYAML( + dockerClusterConfigCRDDefinition, + ) + awsClusterConfigVariableSchema = variables.MustSchemaFromCRDYAML( + awsClusterConfigCRDDefinition, + ) + nutanixClusterConfigVariableSchema = variables.MustSchemaFromCRDYAML( + nutanixClusterConfigCRDDefinition, + ) ) // +kubebuilder:object:root=true -// ClusterConfig is the Schema for the clusterconfigs API. -type ClusterConfig struct { +// AWSClusterConfig is the Schema for the awsclusterconfigs API. +type AWSClusterConfig struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` // +optional - Spec ClusterConfigSpec `json:"spec,omitempty"` + Spec AWSClusterConfigSpec `json:"spec,omitempty"` +} + +func (s AWSClusterConfig) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect. + return awsClusterConfigVariableSchema } -// ClusterConfigSpec defines the desired state of ClusterConfig. -type ClusterConfigSpec struct { +// AWSClusterConfigSpec defines the desired state of ClusterConfig. +type AWSClusterConfigSpec struct { // +optional AWS *AWSSpec `json:"aws,omitempty"` + + GenericClusterConfigSpec `json:",inline"` + + // +optional + ControlPlane *AWSNodeConfigSpec `json:"controlPlane,omitempty"` +} + +// +kubebuilder:object:root=true + +// DockerClusterConfig is the Schema for the dockerclusterconfigs API. +type DockerClusterConfig struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + // +optional + Spec DockerClusterConfigSpec `json:"spec,omitempty"` +} + +func (s DockerClusterConfig) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect. + return dockerClusterConfigVariableSchema +} + +// DockerClusterConfigSpec defines the desired state of DockerClusterConfig. +type DockerClusterConfigSpec struct { // +optional Docker *DockerSpec `json:"docker,omitempty"` + + GenericClusterConfigSpec `json:",inline"` + + // +optional + ControlPlane *DockerNodeConfigSpec `json:"controlPlane,omitempty"` +} + +// +kubebuilder:object:root=true + +// NutanixClusterConfig is the Schema for the nutanixclusterconfigs API. +type NutanixClusterConfig struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + // +optional + Spec NutanixClusterConfigSpec `json:"spec,omitempty"` +} + +func (s NutanixClusterConfig) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect. + return nutanixClusterConfigVariableSchema +} + +// NutanixClusterConfigSpec defines the desired state of NutanixClusterConfig. +type NutanixClusterConfigSpec struct { // +optional Nutanix *NutanixSpec `json:"nutanix,omitempty"` - GenericClusterConfig `json:",inline"` + GenericClusterConfigSpec `json:",inline"` // +optional - ControlPlane *NodeConfigSpec `json:"controlPlane,omitempty"` + ControlPlane *NutanixNodeConfigSpec `json:"controlPlane,omitempty"` } -func (s ClusterConfigSpec) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect. - clusterConfigProps := GenericClusterConfig{}.VariableSchema() - switch { - case s.AWS != nil: - maps.Copy( - clusterConfigProps.OpenAPIV3Schema.Properties, - map[string]clusterv1.JSONSchemaProps{ - AWSVariableName: s.AWS.VariableSchema().OpenAPIV3Schema, - "controlPlane": s.ControlPlane.VariableSchema().OpenAPIV3Schema, - }, - ) - case s.Docker != nil: - maps.Copy( - clusterConfigProps.OpenAPIV3Schema.Properties, - map[string]clusterv1.JSONSchemaProps{ - "docker": DockerSpec{}.VariableSchema().OpenAPIV3Schema, - "controlPlane": NodeConfigSpec{ - Docker: &DockerNodeSpec{}, - }.VariableSchema().OpenAPIV3Schema, - }, - ) - case s.Nutanix != nil: - maps.Copy( - clusterConfigProps.OpenAPIV3Schema.Properties, - map[string]clusterv1.JSONSchemaProps{ - NutanixVariableName: NutanixSpec{}.VariableSchema().OpenAPIV3Schema, - "controlPlane": NodeConfigSpec{ - Nutanix: &NutanixNodeSpec{}, - }.VariableSchema().OpenAPIV3Schema, - }, - ) - } +// +kubebuilder:object:root=true - return clusterConfigProps +// GenericClusterConfig is the Schema for the clusterconfigs API. +type GenericClusterConfig struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + // +optional + Spec GenericClusterConfigSpec `json:"spec,omitempty"` } -func NewAWSClusterConfigSpec() *ClusterConfigSpec { - return &ClusterConfigSpec{ - AWS: &AWSSpec{}, - ControlPlane: &NodeConfigSpec{ - AWS: NewAWSControlPlaneNodeSpec(), - }, - } +func (s GenericClusterConfig) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect. + return genericClusterConfigVariableSchema } -// GenericClusterConfig defines the generic cluster configdesired. -type GenericClusterConfig struct { +// GenericClusterConfigSpec defines the desired state of GenericClusterConfig. +type GenericClusterConfigSpec struct { // +optional KubernetesImageRepository *KubernetesImageRepository `json:"kubernetesImageRepository,omitempty"` @@ -144,41 +185,9 @@ type GenericClusterConfig struct { Users Users `json:"users,omitempty"` } -func (s GenericClusterConfig) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect. - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "Cluster configuration", - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "addons": Addons{}.VariableSchema().OpenAPIV3Schema, - "etcd": Etcd{}.VariableSchema().OpenAPIV3Schema, - "extraAPIServerCertSANs": ExtraAPIServerCertSANs{}.VariableSchema().OpenAPIV3Schema, - "proxy": HTTPProxy{}.VariableSchema().OpenAPIV3Schema, - "kubernetesImageRepository": KubernetesImageRepository( - "", - ).VariableSchema(). - OpenAPIV3Schema, - "imageRegistries": ImageRegistries{}.VariableSchema().OpenAPIV3Schema, - "globalImageRegistryMirror": GlobalImageRegistryMirror{}.VariableSchema().OpenAPIV3Schema, - "users": Users{}.VariableSchema().OpenAPIV3Schema, - }, - }, - } -} - // KubernetesImageRepository required for overriding Kubernetes image repository. type KubernetesImageRepository string -func (KubernetesImageRepository) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "Sets the Kubernetes image repository used for the KubeadmControlPlane.", - Type: "string", - Pattern: patterns.Anchored(patterns.ImageRepository), - }, - } -} - func (v KubernetesImageRepository) String() string { return string(v) } @@ -193,43 +202,12 @@ type Image struct { Tag string `json:"tag,omitempty"` } -func (Image) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "repository": { - Description: "Image repository to pull from.", - Type: "string", - Pattern: patterns.Anchored(patterns.ImageRepository), - }, - "tag": { - Description: "Image tag to use.", - Type: "string", - Pattern: patterns.Anchored(patterns.ImageTag), - }, - }, - }, - } -} - type Etcd struct { // Image required for overriding etcd image details. // +optional Image *Image `json:"image,omitempty"` } -func (Etcd) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "image": Image{}.VariableSchema().OpenAPIV3Schema, - }, - }, - } -} - // HTTPProxy required for providing proxy configuration. type HTTPProxy struct { // HTTP proxy. @@ -245,56 +223,9 @@ type HTTPProxy struct { AdditionalNo []string `json:"additionalNo"` } -func (HTTPProxy) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "http": { - Description: "HTTP proxy value.", - Type: "string", - }, - "https": { - Description: "HTTPS proxy value.", - Type: "string", - }, - "additionalNo": { - Description: "Additional No Proxy list that will be added to the automatically calculated " + - "values required for cluster internal network. " + - "Default value: localhost,127.0.0.1,,,kubernetes," + - "kubernetes.default,.svc,.svc.", - Type: "array", - Items: &clusterv1.JSONSchemaProps{ - Type: "string", - }, - }, - }, - }, - } -} - // ExtraAPIServerCertSANs required for providing API server cert SANs. type ExtraAPIServerCertSANs []string -func (ExtraAPIServerCertSANs) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: fmt.Sprintf( - //nolint:lll // its a user facing message - "Subject Alternative Names for the API Server signing cert. For Docker %s are injected automatically. For Nutanix %s are injected automatically.", - strings.Join(DefaultDockerCertSANs, ","), - strings.Join(DefaultNutanixCertSANs, ","), - ), - Type: "array", - UniqueItems: true, - Items: &clusterv1.JSONSchemaProps{ - Type: "string", - Pattern: patterns.Anchored(patterns.DNS1123Subdomain), - }, - }, - } -} - type RegistryCredentials struct { // A reference to the Secret containing the registry credentials and optional CA certificate // using the keys `username`, `password` and `ca.crt`. @@ -303,30 +234,6 @@ type RegistryCredentials struct { SecretRef *corev1.LocalObjectReference `json:"secretRef,omitempty"` } -func (RegistryCredentials) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "secretRef": { - Description: "A reference to the Secret containing the registry credentials and optional CA certificate. " + - "The Secret should have keys 'username', 'password' and optional 'ca.crt'. " + - "This credentials Secret is not required for some registries, e.g. ECR.", - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "name": { - Description: "The name of the Secret containing the registry credentials. This Secret must exist in " + - "the same namespace as the Cluster.", - Type: "string", - }, - }, - Required: []string{"name"}, - }, - }, - }, - } -} - // GlobalImageRegistryMirror sets default mirror configuration for all the image registries. type GlobalImageRegistryMirror struct { // Registry URL. @@ -337,24 +244,6 @@ type GlobalImageRegistryMirror struct { Credentials *RegistryCredentials `json:"credentials,omitempty"` } -func (GlobalImageRegistryMirror) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "url": { - Description: "Registry mirror URL.", - Type: "string", - Format: "uri", - Pattern: "^https?://", - }, - "credentials": RegistryCredentials{}.VariableSchema().OpenAPIV3Schema, - }, - Required: []string{"url"}, - }, - } -} - type ImageRegistry struct { // Registry URL. URL string `json:"url"` @@ -364,48 +253,10 @@ type ImageRegistry struct { Credentials *RegistryCredentials `json:"credentials,omitempty"` } -func (ImageRegistry) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "url": { - Description: "Registry URL.", - Type: "string", - Format: "uri", - Pattern: "^https?://", - }, - "credentials": RegistryCredentials{}.VariableSchema().OpenAPIV3Schema, - }, - Required: []string{"url"}, - }, - } -} - type ImageRegistries []ImageRegistry -func (ImageRegistries) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "Configuration for image registries.", - Type: "array", - Items: ptr.To(ImageRegistry{}.VariableSchema().OpenAPIV3Schema), - }, - } -} - type Users []User -func (Users) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "Users to add to the machine", - Type: "array", - Items: ptr.To(User{}.VariableSchema().OpenAPIV3Schema), - }, - } -} - // User defines the input for a generated user in cloud-init. type User struct { // Name specifies the user name. @@ -431,46 +282,11 @@ type User struct { Sudo string `json:"sudo,omitempty"` } -func (User) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "object", - Required: []string{"name"}, - Properties: map[string]clusterv1.JSONSchemaProps{ - "name": { - Description: "The username", - Type: "string", - }, - "hashedPassword": { - Description: "The hashed password for the user. Must be in the format of some hash function supported by the OS.", - Type: "string", - // The crypt (5) man page lists regexes for supported hash - // functions. We could validate input against a set of - // regexes, but because the set may be different from the - // set supported by the chosen OS, we might return a false - // negative or positive. For this reason, we do not validate - // the input. - }, - "sshAuthorizedKeys": { - Description: "A list of SSH authorized keys for this user", - Type: "array", - Items: &clusterv1.JSONSchemaProps{ - // No description, because the one for the parent array is enough. - Type: "string", - }, - }, - "sudo": { - Description: "The sudo rule that applies to this user", - Type: "string", - // A sudo rule is defined using an EBNF grammar, and must be - // parsed to be validated. We have decided to not integrate - // a sudo rule parser, so we do not validate the input. - }, - }, - }, - } -} - func init() { - SchemeBuilder.Register(&ClusterConfig{}) + SchemeBuilder.Register( + &AWSClusterConfig{}, + &DockerClusterConfig{}, + &NutanixClusterConfig{}, + &GenericClusterConfig{}, + ) } diff --git a/api/v1alpha1/common_types.go b/api/v1alpha1/common_types.go index d1b0851d2..a9132ca50 100644 --- a/api/v1alpha1/common_types.go +++ b/api/v1alpha1/common_types.go @@ -4,10 +4,7 @@ package v1alpha1 import ( - "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/variables" ) const ( @@ -36,27 +33,3 @@ type ObjectMeta struct { } type ControlPlaneEndpointSpec clusterv1.APIEndpoint - -func (ControlPlaneEndpointSpec) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "Kubernetes control-plane endpoint configuration", - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "host": { - Description: "host ip/fqdn for control plane API Server", - Type: "string", - MinLength: ptr.To[int64](1), - }, - "port": { - Description: "port for control plane API Server", - Type: "integer", - Default: variables.MustMarshal(APIServerPort), - Minimum: ptr.To[int64](1), - Maximum: ptr.To[int64](65535), - }, - }, - Required: []string{"host", "port"}, - }, - } -} diff --git a/api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml new file mode 100644 index 000000000..87ec0f782 --- /dev/null +++ b/api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml @@ -0,0 +1,372 @@ +# Copyright 2023 D2iQ, Inc. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: (devel) + name: awsclusterconfigs.caren.nutanix.com +spec: + group: caren.nutanix.com + names: + kind: AWSClusterConfig + listKind: AWSClusterConfigList + plural: awsclusterconfigs + singular: awsclusterconfig + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: AWSClusterConfig is the Schema for the awsclusterconfigs API. + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: AWSClusterConfigSpec defines the desired state of ClusterConfig. + properties: + addons: + properties: + ccm: + description: CCM tells us to enable or disable the cloud provider + interface. + properties: + credentials: + description: A reference to the Secret for credential information + for the target Prism Central instance + properties: + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid? + type: string + type: object + x-kubernetes-map-type: atomic + type: object + clusterAutoscaler: + description: ClusterAutoscaler tells us to enable or disable the + cluster-autoscaler addon. + properties: + strategy: + type: string + type: object + cni: + description: CNI required for providing CNI configuration. + properties: + provider: + type: string + strategy: + type: string + type: object + csi: + properties: + defaultStorage: + properties: + providerName: + type: string + storageClassConfigName: + type: string + required: + - providerName + - storageClassConfigName + type: object + providers: + items: + properties: + credentials: + description: |- + LocalObjectReference contains enough information to let you locate the + referenced object inside the same namespace. + properties: + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid? + type: string + type: object + x-kubernetes-map-type: atomic + name: + type: string + storageClassConfig: + items: + properties: + allowExpansion: + type: boolean + name: + type: string + parameters: + additionalProperties: + type: string + type: object + reclaimPolicy: + description: PersistentVolumeReclaimPolicy describes + a policy for end-of-life maintenance of persistent + volumes. + type: string + volumeBindingMode: + description: VolumeBindingMode indicates how PersistentVolumeClaims + should be bound. + type: string + required: + - name + type: object + type: array + strategy: + type: string + required: + - name + - strategy + type: object + type: array + type: object + nfd: + description: NFD tells us to enable or disable the node feature + discovery addon. + properties: + strategy: + type: string + type: object + type: object + aws: + properties: + controlPlaneLoadBalancer: + description: AWSLoadBalancerSpec configures an AWS control-plane + LoadBalancer. + properties: + scheme: + default: internet-facing + description: Scheme sets the scheme of the load balancer (defaults + to internet-facing) + enum: + - internet-facing + - internal + type: string + type: object + network: + properties: + subnets: + items: + description: SubnetSpec configures an AWS Subnet. + properties: + id: + description: ID defines a unique identifier to reference + this resource. + type: string + required: + - id + type: object + type: array + vpc: + properties: + id: + description: ID is the vpc-id of the VPC this provider + should use to create resources. + type: string + type: object + type: object + region: + description: AWS region to create cluster in. + type: string + type: object + controlPlane: + description: |- + AWSNodeConfigSpec defines the desired state of AWSNodeConfig. + Place any configuration that can be applied to individual Nodes here. + Otherwise, it should go into the ClusterConfigSpec. + properties: + aws: + properties: + additionalSecurityGroups: + items: + properties: + id: + description: ID is the id of the security group + type: string + type: object + type: array + ami: + description: |- + AMI or AMI Lookup arguments for machine image of a AWS machine. + If both AMI ID and AMI lookup arguments are provided then AMI ID takes precedence + properties: + id: + description: ID is an explicit AMI to use. + type: string + lookup: + description: Lookup is the lookup arguments for the AMI. + properties: + baseOS: + description: BaseOS is the name of the base os for + image lookup + type: string + format: + description: Format is the AMI naming format + type: string + org: + description: Org is the AWS Organization ID to use + for image lookup + type: string + type: object + type: object + iamInstanceProfile: + type: string + instanceType: + type: string + type: object + type: object + etcd: + properties: + image: + description: Image required for overriding etcd image details. + properties: + repository: + description: Repository is used to override the image repository + to pull from. + type: string + tag: + description: Tag is used to override the default image tag. + type: string + type: object + type: object + extraAPIServerCertSANs: + description: ExtraAPIServerCertSANs required for providing API server + cert SANs. + items: + type: string + type: array + globalImageRegistryMirror: + description: GlobalImageRegistryMirror sets default mirror configuration + for all the image registries. + properties: + credentials: + description: Credentials and CA certificate for the image registry + mirror + properties: + secretRef: + description: |- + A reference to the Secret containing the registry credentials and optional CA certificate + using the keys `username`, `password` and `ca.crt`. + This credentials Secret is not required for some registries, e.g. ECR. + properties: + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid? + type: string + type: object + x-kubernetes-map-type: atomic + type: object + url: + description: Registry URL. + type: string + required: + - url + type: object + imageRegistries: + items: + properties: + credentials: + description: Credentials and CA certificate for the image registry + properties: + secretRef: + description: |- + A reference to the Secret containing the registry credentials and optional CA certificate + using the keys `username`, `password` and `ca.crt`. + This credentials Secret is not required for some registries, e.g. ECR. + properties: + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid? + type: string + type: object + x-kubernetes-map-type: atomic + type: object + url: + description: Registry URL. + type: string + required: + - url + type: object + type: array + kubernetesImageRepository: + description: KubernetesImageRepository required for overriding Kubernetes + image repository. + type: string + proxy: + description: HTTPProxy required for providing proxy configuration. + properties: + additionalNo: + description: |- + AdditionalNo Proxy list that will be added to the automatically calculated + values that will apply no_proxy configuration for cluster internal network. + Default values: localhost,127.0.0.1,,,kubernetes + ,kubernetes.default,.svc,.svc. + items: + type: string + type: array + http: + description: HTTP proxy. + type: string + https: + description: HTTPS proxy. + type: string + required: + - additionalNo + type: object + users: + items: + description: User defines the input for a generated user in cloud-init. + properties: + hashedPassword: + description: |- + HashedPassword is a hashed password for the user, formatted as described + by the crypt(5) man page. See your distribution's documentation for + instructions to create a hashed password. + An empty string is not marshalled, because it is not a valid value. + type: string + name: + description: Name specifies the user name. + type: string + sshAuthorizedKeys: + description: |- + SSHAuthorizedKeys is a list of public SSH keys to write to the + machine. Use the corresponding private SSH keys to authenticate. See SSH + documentation for instructions to create a key pair. + items: + type: string + type: array + sudo: + description: |- + Sudo is a sudo user specification, formatted as described in the sudo + documentation. + An empty string is not marshalled, because it is not a valid value. + type: string + required: + - name + type: object + type: array + type: object + type: object + served: true + storage: true diff --git a/api/v1alpha1/crds/caren.nutanix.com_awsnodeconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_awsnodeconfigs.yaml new file mode 100644 index 000000000..f019bb5d5 --- /dev/null +++ b/api/v1alpha1/crds/caren.nutanix.com_awsnodeconfigs.yaml @@ -0,0 +1,89 @@ +# Copyright 2023 D2iQ, Inc. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: (devel) + name: awsnodeconfigs.caren.nutanix.com +spec: + group: caren.nutanix.com + names: + kind: AWSNodeConfig + listKind: AWSNodeConfigList + plural: awsnodeconfigs + singular: awsnodeconfig + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: AWSNodeConfig is the Schema for the awsnodeconfigs API. + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: |- + AWSNodeConfigSpec defines the desired state of AWSNodeConfig. + Place any configuration that can be applied to individual Nodes here. + Otherwise, it should go into the ClusterConfigSpec. + properties: + aws: + properties: + additionalSecurityGroups: + items: + properties: + id: + description: ID is the id of the security group + type: string + type: object + type: array + ami: + description: |- + AMI or AMI Lookup arguments for machine image of a AWS machine. + If both AMI ID and AMI lookup arguments are provided then AMI ID takes precedence + properties: + id: + description: ID is an explicit AMI to use. + type: string + lookup: + description: Lookup is the lookup arguments for the AMI. + properties: + baseOS: + description: BaseOS is the name of the base os for image + lookup + type: string + format: + description: Format is the AMI naming format + type: string + org: + description: Org is the AWS Organization ID to use for + image lookup + type: string + type: object + type: object + iamInstanceProfile: + type: string + instanceType: + type: string + type: object + type: object + type: object + served: true + storage: true diff --git a/api/v1alpha1/crds/caren.nutanix.com_dockerclusterconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_dockerclusterconfigs.yaml new file mode 100644 index 000000000..31e67a3b6 --- /dev/null +++ b/api/v1alpha1/crds/caren.nutanix.com_dockerclusterconfigs.yaml @@ -0,0 +1,297 @@ +# Copyright 2023 D2iQ, Inc. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: (devel) + name: dockerclusterconfigs.caren.nutanix.com +spec: + group: caren.nutanix.com + names: + kind: DockerClusterConfig + listKind: DockerClusterConfigList + plural: dockerclusterconfigs + singular: dockerclusterconfig + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: DockerClusterConfig is the Schema for the dockerclusterconfigs + API. + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: DockerClusterConfigSpec defines the desired state of DockerClusterConfig. + properties: + addons: + properties: + ccm: + description: CCM tells us to enable or disable the cloud provider + interface. + properties: + credentials: + description: A reference to the Secret for credential information + for the target Prism Central instance + properties: + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid? + type: string + type: object + x-kubernetes-map-type: atomic + type: object + clusterAutoscaler: + description: ClusterAutoscaler tells us to enable or disable the + cluster-autoscaler addon. + properties: + strategy: + type: string + type: object + cni: + description: CNI required for providing CNI configuration. + properties: + provider: + type: string + strategy: + type: string + type: object + csi: + properties: + defaultStorage: + properties: + providerName: + type: string + storageClassConfigName: + type: string + required: + - providerName + - storageClassConfigName + type: object + providers: + items: + properties: + credentials: + description: |- + LocalObjectReference contains enough information to let you locate the + referenced object inside the same namespace. + properties: + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid? + type: string + type: object + x-kubernetes-map-type: atomic + name: + type: string + storageClassConfig: + items: + properties: + allowExpansion: + type: boolean + name: + type: string + parameters: + additionalProperties: + type: string + type: object + reclaimPolicy: + description: PersistentVolumeReclaimPolicy describes + a policy for end-of-life maintenance of persistent + volumes. + type: string + volumeBindingMode: + description: VolumeBindingMode indicates how PersistentVolumeClaims + should be bound. + type: string + required: + - name + type: object + type: array + strategy: + type: string + required: + - name + - strategy + type: object + type: array + type: object + nfd: + description: NFD tells us to enable or disable the node feature + discovery addon. + properties: + strategy: + type: string + type: object + type: object + controlPlane: + description: DockerNodeConfigSpec defines the desired state of DockerNodeSpec. + properties: + docker: + properties: + customImage: + type: string + type: object + type: object + docker: + type: object + etcd: + properties: + image: + description: Image required for overriding etcd image details. + properties: + repository: + description: Repository is used to override the image repository + to pull from. + type: string + tag: + description: Tag is used to override the default image tag. + type: string + type: object + type: object + extraAPIServerCertSANs: + description: ExtraAPIServerCertSANs required for providing API server + cert SANs. + items: + type: string + type: array + globalImageRegistryMirror: + description: GlobalImageRegistryMirror sets default mirror configuration + for all the image registries. + properties: + credentials: + description: Credentials and CA certificate for the image registry + mirror + properties: + secretRef: + description: |- + A reference to the Secret containing the registry credentials and optional CA certificate + using the keys `username`, `password` and `ca.crt`. + This credentials Secret is not required for some registries, e.g. ECR. + properties: + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid? + type: string + type: object + x-kubernetes-map-type: atomic + type: object + url: + description: Registry URL. + type: string + required: + - url + type: object + imageRegistries: + items: + properties: + credentials: + description: Credentials and CA certificate for the image registry + properties: + secretRef: + description: |- + A reference to the Secret containing the registry credentials and optional CA certificate + using the keys `username`, `password` and `ca.crt`. + This credentials Secret is not required for some registries, e.g. ECR. + properties: + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid? + type: string + type: object + x-kubernetes-map-type: atomic + type: object + url: + description: Registry URL. + type: string + required: + - url + type: object + type: array + kubernetesImageRepository: + description: KubernetesImageRepository required for overriding Kubernetes + image repository. + type: string + proxy: + description: HTTPProxy required for providing proxy configuration. + properties: + additionalNo: + description: |- + AdditionalNo Proxy list that will be added to the automatically calculated + values that will apply no_proxy configuration for cluster internal network. + Default values: localhost,127.0.0.1,,,kubernetes + ,kubernetes.default,.svc,.svc. + items: + type: string + type: array + http: + description: HTTP proxy. + type: string + https: + description: HTTPS proxy. + type: string + required: + - additionalNo + type: object + users: + items: + description: User defines the input for a generated user in cloud-init. + properties: + hashedPassword: + description: |- + HashedPassword is a hashed password for the user, formatted as described + by the crypt(5) man page. See your distribution's documentation for + instructions to create a hashed password. + An empty string is not marshalled, because it is not a valid value. + type: string + name: + description: Name specifies the user name. + type: string + sshAuthorizedKeys: + description: |- + SSHAuthorizedKeys is a list of public SSH keys to write to the + machine. Use the corresponding private SSH keys to authenticate. See SSH + documentation for instructions to create a key pair. + items: + type: string + type: array + sudo: + description: |- + Sudo is a sudo user specification, formatted as described in the sudo + documentation. + An empty string is not marshalled, because it is not a valid value. + type: string + required: + - name + type: object + type: array + type: object + type: object + served: true + storage: true diff --git a/api/v1alpha1/crds/caren.nutanix.com_dockernodeconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_dockernodeconfigs.yaml new file mode 100644 index 000000000..8bf792187 --- /dev/null +++ b/api/v1alpha1/crds/caren.nutanix.com_dockernodeconfigs.yaml @@ -0,0 +1,52 @@ +# Copyright 2023 D2iQ, Inc. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: (devel) + name: dockernodeconfigs.caren.nutanix.com +spec: + group: caren.nutanix.com + names: + kind: DockerNodeConfig + listKind: DockerNodeConfigList + plural: dockernodeconfigs + singular: dockernodeconfig + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: DockerNodeConfig is the Schema for the dockernodeconfigs API. + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: DockerNodeConfigSpec defines the desired state of DockerNodeSpec. + properties: + docker: + properties: + customImage: + type: string + type: object + type: object + type: object + served: true + storage: true diff --git a/api/v1alpha1/crds/caren.nutanix.com_genericclusterconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_genericclusterconfigs.yaml new file mode 100644 index 000000000..df7f5fecb --- /dev/null +++ b/api/v1alpha1/crds/caren.nutanix.com_genericclusterconfigs.yaml @@ -0,0 +1,285 @@ +# Copyright 2023 D2iQ, Inc. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: (devel) + name: genericclusterconfigs.caren.nutanix.com +spec: + group: caren.nutanix.com + names: + kind: GenericClusterConfig + listKind: GenericClusterConfigList + plural: genericclusterconfigs + singular: genericclusterconfig + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: GenericClusterConfig is the Schema for the clusterconfigs API. + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: GenericClusterConfigSpec defines the desired state of GenericClusterConfig. + properties: + addons: + properties: + ccm: + description: CCM tells us to enable or disable the cloud provider + interface. + properties: + credentials: + description: A reference to the Secret for credential information + for the target Prism Central instance + properties: + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid? + type: string + type: object + x-kubernetes-map-type: atomic + type: object + clusterAutoscaler: + description: ClusterAutoscaler tells us to enable or disable the + cluster-autoscaler addon. + properties: + strategy: + type: string + type: object + cni: + description: CNI required for providing CNI configuration. + properties: + provider: + type: string + strategy: + type: string + type: object + csi: + properties: + defaultStorage: + properties: + providerName: + type: string + storageClassConfigName: + type: string + required: + - providerName + - storageClassConfigName + type: object + providers: + items: + properties: + credentials: + description: |- + LocalObjectReference contains enough information to let you locate the + referenced object inside the same namespace. + properties: + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid? + type: string + type: object + x-kubernetes-map-type: atomic + name: + type: string + storageClassConfig: + items: + properties: + allowExpansion: + type: boolean + name: + type: string + parameters: + additionalProperties: + type: string + type: object + reclaimPolicy: + description: PersistentVolumeReclaimPolicy describes + a policy for end-of-life maintenance of persistent + volumes. + type: string + volumeBindingMode: + description: VolumeBindingMode indicates how PersistentVolumeClaims + should be bound. + type: string + required: + - name + type: object + type: array + strategy: + type: string + required: + - name + - strategy + type: object + type: array + type: object + nfd: + description: NFD tells us to enable or disable the node feature + discovery addon. + properties: + strategy: + type: string + type: object + type: object + etcd: + properties: + image: + description: Image required for overriding etcd image details. + properties: + repository: + description: Repository is used to override the image repository + to pull from. + type: string + tag: + description: Tag is used to override the default image tag. + type: string + type: object + type: object + extraAPIServerCertSANs: + description: ExtraAPIServerCertSANs required for providing API server + cert SANs. + items: + type: string + type: array + globalImageRegistryMirror: + description: GlobalImageRegistryMirror sets default mirror configuration + for all the image registries. + properties: + credentials: + description: Credentials and CA certificate for the image registry + mirror + properties: + secretRef: + description: |- + A reference to the Secret containing the registry credentials and optional CA certificate + using the keys `username`, `password` and `ca.crt`. + This credentials Secret is not required for some registries, e.g. ECR. + properties: + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid? + type: string + type: object + x-kubernetes-map-type: atomic + type: object + url: + description: Registry URL. + type: string + required: + - url + type: object + imageRegistries: + items: + properties: + credentials: + description: Credentials and CA certificate for the image registry + properties: + secretRef: + description: |- + A reference to the Secret containing the registry credentials and optional CA certificate + using the keys `username`, `password` and `ca.crt`. + This credentials Secret is not required for some registries, e.g. ECR. + properties: + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid? + type: string + type: object + x-kubernetes-map-type: atomic + type: object + url: + description: Registry URL. + type: string + required: + - url + type: object + type: array + kubernetesImageRepository: + description: KubernetesImageRepository required for overriding Kubernetes + image repository. + type: string + proxy: + description: HTTPProxy required for providing proxy configuration. + properties: + additionalNo: + description: |- + AdditionalNo Proxy list that will be added to the automatically calculated + values that will apply no_proxy configuration for cluster internal network. + Default values: localhost,127.0.0.1,,,kubernetes + ,kubernetes.default,.svc,.svc. + items: + type: string + type: array + http: + description: HTTP proxy. + type: string + https: + description: HTTPS proxy. + type: string + required: + - additionalNo + type: object + users: + items: + description: User defines the input for a generated user in cloud-init. + properties: + hashedPassword: + description: |- + HashedPassword is a hashed password for the user, formatted as described + by the crypt(5) man page. See your distribution's documentation for + instructions to create a hashed password. + An empty string is not marshalled, because it is not a valid value. + type: string + name: + description: Name specifies the user name. + type: string + sshAuthorizedKeys: + description: |- + SSHAuthorizedKeys is a list of public SSH keys to write to the + machine. Use the corresponding private SSH keys to authenticate. See SSH + documentation for instructions to create a key pair. + items: + type: string + type: array + sudo: + description: |- + Sudo is a sudo user specification, formatted as described in the sudo + documentation. + An empty string is not marshalled, because it is not a valid value. + type: string + required: + - name + type: object + type: array + type: object + type: object + served: true + storage: true diff --git a/api/v1alpha1/crds/caren.nutanix.com_clusterconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_nutanixclusterconfigs.yaml similarity index 84% rename from api/v1alpha1/crds/caren.nutanix.com_clusterconfigs.yaml rename to api/v1alpha1/crds/caren.nutanix.com_nutanixclusterconfigs.yaml index 317feb268..428f0e7d5 100644 --- a/api/v1alpha1/crds/caren.nutanix.com_clusterconfigs.yaml +++ b/api/v1alpha1/crds/caren.nutanix.com_nutanixclusterconfigs.yaml @@ -6,20 +6,21 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: (devel) - name: clusterconfigs.caren.nutanix.com + name: nutanixclusterconfigs.caren.nutanix.com spec: group: caren.nutanix.com names: - kind: ClusterConfig - listKind: ClusterConfigList - plural: clusterconfigs - singular: clusterconfig + kind: NutanixClusterConfig + listKind: NutanixClusterConfigList + plural: nutanixclusterconfigs + singular: nutanixclusterconfig scope: Namespaced versions: - name: v1alpha1 schema: openAPIV3Schema: - description: ClusterConfig is the Schema for the clusterconfigs API. + description: NutanixClusterConfig is the Schema for the nutanixclusterconfigs + API. properties: apiVersion: description: |- @@ -39,7 +40,7 @@ spec: metadata: type: object spec: - description: ClusterConfigSpec defines the desired state of ClusterConfig. + description: NutanixClusterConfigSpec defines the desired state of NutanixClusterConfig. properties: addons: properties: @@ -145,97 +146,9 @@ spec: type: string type: object type: object - aws: - properties: - controlPlaneLoadBalancer: - description: AWSLoadBalancerSpec configures an AWS control-plane - LoadBalancer. - properties: - scheme: - default: internet-facing - description: Scheme sets the scheme of the load balancer (defaults - to internet-facing) - enum: - - internet-facing - - internal - type: string - type: object - network: - properties: - subnets: - items: - description: SubnetSpec configures an AWS Subnet. - properties: - id: - description: ID defines a unique identifier to reference - this resource. - type: string - required: - - id - type: object - type: array - vpc: - properties: - id: - description: ID is the vpc-id of the VPC this provider - should use to create resources. - type: string - type: object - type: object - region: - description: AWS region to create cluster in. - type: string - type: object controlPlane: - description: |- - NodeConfigSpec defines the desired state of NodeConfig. - Place any configuration that can be applied to individual Nodes here. - Otherwise, it should go into the ClusterConfigSpec. + description: NutanixNodeSpec defines the desired state of NutanixNodeSpec. properties: - aws: - properties: - additionalSecurityGroups: - items: - properties: - id: - description: ID is the id of the security group - type: string - type: object - type: array - ami: - description: |- - AMI or AMI Lookup arguments for machine image of a AWS machine. - If both AMI ID and AMI lookup arguments are provided then AMI ID takes precedence - properties: - id: - description: ID is an explicit AMI to use. - type: string - lookup: - description: Lookup is the lookup arguments for the AMI. - properties: - baseOS: - description: BaseOS is the name of the base os for - image lookup - type: string - format: - description: Format is the AMI naming format - type: string - org: - description: Org is the AWS Organization ID to use - for image lookup - type: string - type: object - type: object - iamInstanceProfile: - type: string - instanceType: - type: string - type: object - docker: - properties: - customImage: - type: string - type: object nutanix: properties: machineDetails: @@ -392,8 +305,6 @@ spec: - machineDetails type: object type: object - docker: - type: object etcd: properties: image: diff --git a/api/v1alpha1/crds/caren.nutanix.com_nodeconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_nutanixnodeconfigs.yaml similarity index 79% rename from api/v1alpha1/crds/caren.nutanix.com_nodeconfigs.yaml rename to api/v1alpha1/crds/caren.nutanix.com_nutanixnodeconfigs.yaml index 35eada48a..6ff597a9c 100644 --- a/api/v1alpha1/crds/caren.nutanix.com_nodeconfigs.yaml +++ b/api/v1alpha1/crds/caren.nutanix.com_nutanixnodeconfigs.yaml @@ -6,20 +6,20 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: (devel) - name: nodeconfigs.caren.nutanix.com + name: nutanixnodeconfigs.caren.nutanix.com spec: group: caren.nutanix.com names: - kind: NodeConfig - listKind: NodeConfigList - plural: nodeconfigs - singular: nodeconfig + kind: NutanixNodeConfig + listKind: NutanixNodeConfigList + plural: nutanixnodeconfigs + singular: nutanixnodeconfig scope: Namespaced versions: - name: v1alpha1 schema: openAPIV3Schema: - description: NodeConfig is the Schema for the workerconfigs API. + description: NutanixNodeConfig is the Schema for the nutanixnodeconfigs API. properties: apiVersion: description: |- @@ -39,55 +39,8 @@ spec: metadata: type: object spec: - description: |- - NodeConfigSpec defines the desired state of NodeConfig. - Place any configuration that can be applied to individual Nodes here. - Otherwise, it should go into the ClusterConfigSpec. + description: NutanixNodeSpec defines the desired state of NutanixNodeSpec. properties: - aws: - properties: - additionalSecurityGroups: - items: - properties: - id: - description: ID is the id of the security group - type: string - type: object - type: array - ami: - description: |- - AMI or AMI Lookup arguments for machine image of a AWS machine. - If both AMI ID and AMI lookup arguments are provided then AMI ID takes precedence - properties: - id: - description: ID is an explicit AMI to use. - type: string - lookup: - description: Lookup is the lookup arguments for the AMI. - properties: - baseOS: - description: BaseOS is the name of the base os for image - lookup - type: string - format: - description: Format is the AMI naming format - type: string - org: - description: Org is the AWS Organization ID to use for - image lookup - type: string - type: object - type: object - iamInstanceProfile: - type: string - instanceType: - type: string - type: object - docker: - properties: - customImage: - type: string - type: object nutanix: properties: machineDetails: diff --git a/api/v1alpha1/docker_node_types.go b/api/v1alpha1/docker_node_types.go index 268194eee..cad61fd78 100644 --- a/api/v1alpha1/docker_node_types.go +++ b/api/v1alpha1/docker_node_types.go @@ -14,18 +14,6 @@ type DockerNodeSpec struct { CustomImage *OCIImage `json:"customImage,omitempty"` } -func (DockerNodeSpec) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "Docker Node configuration", - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "customImage": OCIImage("").VariableSchema().OpenAPIV3Schema, - }, - }, - } -} - type OCIImage string func (OCIImage) VariableSchema() clusterv1.VariableSchema { diff --git a/api/v1alpha1/node_types.go b/api/v1alpha1/node_types.go deleted file mode 100644 index 7455da6cf..000000000 --- a/api/v1alpha1/node_types.go +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright 2023 D2iQ, Inc. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package v1alpha1 - -import ( - "maps" - - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" -) - -//+kubebuilder:object:root=true - -// NodeConfig is the Schema for the workerconfigs API. -type NodeConfig struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` - - //+optional - Spec NodeConfigSpec `json:"spec,omitempty"` -} - -// NodeConfigSpec defines the desired state of NodeConfig. -// Place any configuration that can be applied to individual Nodes here. -// Otherwise, it should go into the ClusterConfigSpec. -type NodeConfigSpec struct { - // +optional - AWS *AWSNodeSpec `json:"aws,omitempty"` - // +optional - Docker *DockerNodeSpec `json:"docker,omitempty"` - // +optional - Nutanix *NutanixNodeSpec `json:"nutanix,omitempty"` -} - -func (s NodeConfigSpec) VariableSchema() clusterv1.VariableSchema { - nodeConfigProps := GenericNodeConfig{}.VariableSchema() - - switch { - case s.AWS != nil: - maps.Copy( - nodeConfigProps.OpenAPIV3Schema.Properties, - map[string]clusterv1.JSONSchemaProps{ - AWSVariableName: s.AWS.VariableSchema().OpenAPIV3Schema, - }, - ) - case s.Docker != nil: - maps.Copy( - nodeConfigProps.OpenAPIV3Schema.Properties, - map[string]clusterv1.JSONSchemaProps{ - "docker": DockerNodeSpec{}.VariableSchema().OpenAPIV3Schema, - }, - ) - case s.Nutanix != nil: - maps.Copy( - nodeConfigProps.OpenAPIV3Schema.Properties, - map[string]clusterv1.JSONSchemaProps{ - "nutanix": NutanixNodeSpec{}.VariableSchema().OpenAPIV3Schema, - }, - ) - } - - return nodeConfigProps -} - -func NewAWSWorkerConfigSpec() *NodeConfigSpec { - return &NodeConfigSpec{ - AWS: NewAWSWorkerNodeSpec(), - } -} - -type GenericNodeConfig struct{} - -func (GenericNodeConfig) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "Node configuration", - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{}, - }, - } -} - -func init() { - SchemeBuilder.Register(&NodeConfig{}) -} diff --git a/api/v1alpha1/nodeconfig_types.go b/api/v1alpha1/nodeconfig_types.go new file mode 100644 index 000000000..9854652cc --- /dev/null +++ b/api/v1alpha1/nodeconfig_types.go @@ -0,0 +1,97 @@ +// Copyright 2023 D2iQ, Inc. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +package v1alpha1 + +import ( + _ "embed" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" + + "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables" +) + +var ( + //go:embed crds/caren.nutanix.com_dockernodeconfigs.yaml + dockerNodeConfigCRDDefinition []byte + //go:embed crds/caren.nutanix.com_awsnodeconfigs.yaml + awsNodeConfigCRDDefinition []byte + //go:embed crds/caren.nutanix.com_nutanixnodeconfigs.yaml + nutanixNodeConfigCRDDefinition []byte + + dockerNodeConfigVariableSchema = variables.MustSchemaFromCRDYAML(dockerNodeConfigCRDDefinition) + awsNodeConfigVariableSchema = variables.MustSchemaFromCRDYAML(awsNodeConfigCRDDefinition) + nutanixNodeConfigVariableSchema = variables.MustSchemaFromCRDYAML( + nutanixNodeConfigCRDDefinition, + ) +) + +//+kubebuilder:object:root=true + +// AWSNodeConfig is the Schema for the awsnodeconfigs API. +type AWSNodeConfig struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + //+optional + Spec AWSNodeConfigSpec `json:"spec,omitempty"` +} + +func (s AWSNodeConfig) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect. + return awsNodeConfigVariableSchema +} + +// AWSNodeConfigSpec defines the desired state of AWSNodeConfig. +// Place any configuration that can be applied to individual Nodes here. +// Otherwise, it should go into the ClusterConfigSpec. +type AWSNodeConfigSpec struct { + // +optional + AWS *AWSNodeSpec `json:"aws,omitempty"` +} + +//+kubebuilder:object:root=true + +// DockerNodeConfig is the Schema for the dockernodeconfigs API. +type DockerNodeConfig struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + //+optional + Spec DockerNodeConfigSpec `json:"spec,omitempty"` +} + +func (s DockerNodeConfig) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect. + return dockerNodeConfigVariableSchema +} + +// DockerNodeConfigSpec defines the desired state of DockerNodeSpec. +type DockerNodeConfigSpec struct { + // +optional + Docker *DockerNodeSpec `json:"docker,omitempty"` +} + +// +kubebuilder:object:root=true + +// NutanixNodeConfig is the Schema for the nutanixnodeconfigs API. +type NutanixNodeConfig struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + //+optional + Spec NutanixNodeConfigSpec `json:"spec,omitempty"` +} + +func (s NutanixNodeConfig) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect. + return nutanixNodeConfigVariableSchema +} + +// NutanixNodeSpec defines the desired state of NutanixNodeSpec. +type NutanixNodeConfigSpec struct { + // +optional + Nutanix *NutanixNodeSpec `json:"nutanix,omitempty"` +} + +func init() { + SchemeBuilder.Register(&AWSNodeConfig{}, &DockerNodeConfig{}, &NutanixNodeConfig{}) +} diff --git a/api/v1alpha1/nutanix_clusterconfig_types.go b/api/v1alpha1/nutanix_clusterconfig_types.go index 3b46d838d..ec845b7b4 100644 --- a/api/v1alpha1/nutanix_clusterconfig_types.go +++ b/api/v1alpha1/nutanix_clusterconfig_types.go @@ -9,10 +9,7 @@ import ( "strconv" corev1 "k8s.io/api/core/v1" - "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/openapi/patterns" ) const ( @@ -29,19 +26,6 @@ type NutanixSpec struct { PrismCentralEndpoint NutanixPrismCentralEndpointSpec `json:"prismCentralEndpoint"` } -func (NutanixSpec) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "Nutanix cluster configuration", - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "controlPlaneEndpoint": ControlPlaneEndpointSpec{}.VariableSchema().OpenAPIV3Schema, - "prismCentralEndpoint": NutanixPrismCentralEndpointSpec{}.VariableSchema().OpenAPIV3Schema, - }, - }, - } -} - type NutanixPrismCentralEndpointSpec struct { // The URL of Nutanix Prism Central, can be DNS name or an IP address URL string `json:"url"` @@ -60,50 +44,6 @@ type NutanixPrismCentralEndpointSpec struct { Credentials corev1.LocalObjectReference `json:"credentials"` } -func (NutanixPrismCentralEndpointSpec) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "Nutanix Prism Central endpoint configuration", - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "url": { - Description: "The URL of Nutanix Prism Central, can be DNS name or an IP address", - Type: "string", - MinLength: ptr.To[int64](1), - Format: "uri", - Pattern: patterns.HTTPSURL(), - }, - "insecure": { - Description: "Use insecure connection to Prism Central endpoint", - Type: "boolean", - }, - "additionalTrustBundle": { - Description: "A base64 PEM encoded x509 cert for the RootCA " + - "that was used to create the certificate for a Prism Central that uses certificates " + - "that were issued by a non-publicly trusted RootCA." + - "The trust bundle is added to the cert pool used to authenticate the TLS connection " + - "to the Prism Central.", - Type: "string", - Format: "byte", - }, - "credentials": { - Description: "A reference to the Secret for credential information" + - "for the target Prism Central instance", - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "name": { - Description: "The name of the Secret", - Type: "string", - }, - }, - Required: []string{"name"}, - }, - }, - Required: []string{"url", "credentials"}, - }, - } -} - //nolint:gocritic // no need for named return values func (s NutanixPrismCentralEndpointSpec) ParseURL() (string, int32, error) { var prismCentralURL *url.URL diff --git a/api/v1alpha1/nutanix_node_types.go b/api/v1alpha1/nutanix_node_types.go index c028c280a..96d73377e 100644 --- a/api/v1alpha1/nutanix_node_types.go +++ b/api/v1alpha1/nutanix_node_types.go @@ -5,30 +5,14 @@ package v1alpha1 import ( "k8s.io/apimachinery/pkg/api/resource" - "k8s.io/utils/ptr" - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" capxv1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1" - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/variables" ) type NutanixNodeSpec struct { MachineDetails NutanixMachineDetails `json:"machineDetails"` } -func (NutanixNodeSpec) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "Nutanix Node configuration", - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "machineDetails": NutanixMachineDetails{}.VariableSchema().OpenAPIV3Schema, - }, - Required: []string{"machineDetails"}, - }, - } -} - type NutanixMachineDetails struct { // vcpusPerSocket is the number of vCPUs per socket of the VM VCPUsPerSocket int32 `json:"vcpusPerSocket"` @@ -49,7 +33,7 @@ type NutanixMachineDetails struct { // subnet identifies the network subnet to use for the machine. // The identifier (uuid or name) can be obtained from the console or API. - Subnets []NutanixResourceIdentifier `json:"subnets"` + Subnets NutanixResourceIdentifiers `json:"subnets"` // List of categories that need to be added to the machines. Categories must already // exist in Prism Central. One category key can have more than one value. @@ -69,150 +53,14 @@ type NutanixMachineDetails struct { Project *NutanixResourceIdentifier `json:"project,omitempty"` } -func (NutanixMachineDetails) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "Nutanix Machine configuration", - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "vcpusPerSocket": { - Description: "vcpusPerSocket is the number of vCPUs per socket of the VM", - Type: "integer", - }, - "vcpuSockets": { - Description: "vcpuSockets is the number of vCPU sockets of the VM", - Type: "integer", - }, - "memorySize": { - Description: "memorySize is the memory size (in Quantity format) of the VM eg. 4Gi", - Type: "string", - }, - "image": NutanixResourceIdentifier{}.VariableSchemaFromDescription( - //nolint:lll // Long description. - "image identifies the image uploaded to Prism Central (PC). The identifier (uuid or name) can be obtained from the console or API.", - ).OpenAPIV3Schema, - "cluster": NutanixResourceIdentifier{}.VariableSchemaFromDescription( - //nolint:lll // Long description. - "cluster identifies the Prism Element in which the machine will be created. The identifier (uuid or name) can be obtained from the console or API.", - ).OpenAPIV3Schema, - "subnets": { - Type: "array", - Description: "subnets is a list of network subnets to use for the machine", - Items: ptr.To(NutanixResourceIdentifier{}.VariableSchemaFromDescription( - //nolint:lll // Long description. - "subnet identifies the network subnet to use for the machine. The identifier (uuid or name) can be obtained from the console or API.", - ).OpenAPIV3Schema), - }, - "additionalCategories": { - Type: "array", - //nolint:lll // Description is long. - Description: "List of categories that need to be added to the machines. Categories must already exist in Prism Central. One category key can have more than one value.", - Items: ptr.To( - NutanixCategoryIdentifier{}.VariableSchema().OpenAPIV3Schema, - ), - }, - "bootType": NutanixBootType( - capxv1.NutanixBootTypeLegacy, - ).VariableSchema(). - OpenAPIV3Schema, - "systemDiskSize": { - Description: "systemDiskSize is size (in Quantity format) of the system disk of the VM eg. 20Gi", - Type: "string", - }, - "project": NutanixResourceIdentifier{}.VariableSchemaFromDescription( - //nolint:lll // Long description. - "add the virtual machines to the project defined in Prism Central. The project must already be present in the Prism Central.", - ).OpenAPIV3Schema, - }, - Required: []string{ - "vcpusPerSocket", - "vcpuSockets", - "memorySize", - "image", - "cluster", - "subnets", - "systemDiskSize", - }, - }, - } -} - // NutanixIdentifierType is an enumeration of different resource identifier types. type NutanixIdentifierType capxv1.NutanixIdentifierType -func (NutanixIdentifierType) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "string", - Description: "NutanixIdentifierType is an enumeration of different resource identifier types", - Enum: variables.MustMarshalValuesToEnumJSON( - capxv1.NutanixIdentifierUUID, - capxv1.NutanixIdentifierName, - ), - }, - } -} - // NutanixBootType is an enumeration of different boot types. type NutanixBootType capxv1.NutanixBootType -func (NutanixBootType) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "string", - Description: "NutanixBootType is an enumeration of different boot types.", - Enum: variables.MustMarshalValuesToEnumJSON( - capxv1.NutanixBootTypeLegacy, - capxv1.NutanixBootTypeUEFI, - ), - }, - } -} - type NutanixResourceIdentifier capxv1.NutanixResourceIdentifier -func (NutanixResourceIdentifier) VariableSchemaFromDescription( - description string, -) clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "Nutanix Resource Identifier", - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "type": NutanixIdentifierType( - capxv1.NutanixIdentifierName, - ).VariableSchema(). - OpenAPIV3Schema, - "uuid": { - Type: "string", - Description: "uuid is the UUID of the resource in the PC.", - }, - "name": { - Type: "string", - Description: "name is the resource name in the PC.", - }, - }, - }, - } -} - type NutanixCategoryIdentifier capxv1.NutanixCategoryIdentifier -func (NutanixCategoryIdentifier) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "Nutanix Category Identifier", - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "key": { - Type: "string", - Description: "key is the Key of category in PC.", - }, - "value": { - Type: "string", - Description: "value is the category value linked to the category key in PC.", - }, - }, - }, - } -} +type NutanixResourceIdentifiers []NutanixResourceIdentifier diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 01029e04d..fdf550b04 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -48,6 +48,58 @@ func (in *AMISpec) DeepCopy() *AMISpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AWSClusterConfig) DeepCopyInto(out *AWSClusterConfig) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AWSClusterConfig. +func (in *AWSClusterConfig) DeepCopy() *AWSClusterConfig { + if in == nil { + return nil + } + out := new(AWSClusterConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *AWSClusterConfig) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AWSClusterConfigSpec) DeepCopyInto(out *AWSClusterConfigSpec) { + *out = *in + if in.AWS != nil { + in, out := &in.AWS, &out.AWS + *out = new(AWSSpec) + (*in).DeepCopyInto(*out) + } + in.GenericClusterConfigSpec.DeepCopyInto(&out.GenericClusterConfigSpec) + if in.ControlPlane != nil { + in, out := &in.ControlPlane, &out.ControlPlane + *out = new(AWSNodeConfigSpec) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AWSClusterConfigSpec. +func (in *AWSClusterConfigSpec) DeepCopy() *AWSClusterConfigSpec { + if in == nil { + return nil + } + out := new(AWSClusterConfigSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *AWSLoadBalancerSpec) DeepCopyInto(out *AWSLoadBalancerSpec) { *out = *in @@ -93,6 +145,52 @@ func (in *AWSNetwork) DeepCopy() *AWSNetwork { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AWSNodeConfig) DeepCopyInto(out *AWSNodeConfig) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AWSNodeConfig. +func (in *AWSNodeConfig) DeepCopy() *AWSNodeConfig { + if in == nil { + return nil + } + out := new(AWSNodeConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *AWSNodeConfig) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AWSNodeConfigSpec) DeepCopyInto(out *AWSNodeConfigSpec) { + *out = *in + if in.AWS != nil { + in, out := &in.AWS, &out.AWS + *out = new(AWSNodeSpec) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AWSNodeConfigSpec. +func (in *AWSNodeConfigSpec) DeepCopy() *AWSNodeConfigSpec { + if in == nil { + return nil + } + out := new(AWSNodeConfigSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *AWSNodeSpec) DeepCopyInto(out *AWSNodeSpec) { *out = *in @@ -326,25 +424,55 @@ func (in *ClusterAutoscaler) DeepCopy() *ClusterAutoscaler { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ClusterConfig) DeepCopyInto(out *ClusterConfig) { +func (in *ControlPlaneEndpointSpec) DeepCopyInto(out *ControlPlaneEndpointSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ControlPlaneEndpointSpec. +func (in *ControlPlaneEndpointSpec) DeepCopy() *ControlPlaneEndpointSpec { + if in == nil { + return nil + } + out := new(ControlPlaneEndpointSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DefaultStorage) DeepCopyInto(out *DefaultStorage) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DefaultStorage. +func (in *DefaultStorage) DeepCopy() *DefaultStorage { + if in == nil { + return nil + } + out := new(DefaultStorage) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *DockerClusterConfig) DeepCopyInto(out *DockerClusterConfig) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterConfig. -func (in *ClusterConfig) DeepCopy() *ClusterConfig { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DockerClusterConfig. +func (in *DockerClusterConfig) DeepCopy() *DockerClusterConfig { if in == nil { return nil } - out := new(ClusterConfig) + out := new(DockerClusterConfig) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ClusterConfig) DeepCopyObject() runtime.Object { +func (in *DockerClusterConfig) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -352,67 +480,73 @@ func (in *ClusterConfig) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ClusterConfigSpec) DeepCopyInto(out *ClusterConfigSpec) { +func (in *DockerClusterConfigSpec) DeepCopyInto(out *DockerClusterConfigSpec) { *out = *in - if in.AWS != nil { - in, out := &in.AWS, &out.AWS - *out = new(AWSSpec) - (*in).DeepCopyInto(*out) - } if in.Docker != nil { in, out := &in.Docker, &out.Docker *out = new(DockerSpec) **out = **in } - if in.Nutanix != nil { - in, out := &in.Nutanix, &out.Nutanix - *out = new(NutanixSpec) - (*in).DeepCopyInto(*out) - } - in.GenericClusterConfig.DeepCopyInto(&out.GenericClusterConfig) + in.GenericClusterConfigSpec.DeepCopyInto(&out.GenericClusterConfigSpec) if in.ControlPlane != nil { in, out := &in.ControlPlane, &out.ControlPlane - *out = new(NodeConfigSpec) + *out = new(DockerNodeConfigSpec) (*in).DeepCopyInto(*out) } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterConfigSpec. -func (in *ClusterConfigSpec) DeepCopy() *ClusterConfigSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DockerClusterConfigSpec. +func (in *DockerClusterConfigSpec) DeepCopy() *DockerClusterConfigSpec { if in == nil { return nil } - out := new(ClusterConfigSpec) + out := new(DockerClusterConfigSpec) in.DeepCopyInto(out) return out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ControlPlaneEndpointSpec) DeepCopyInto(out *ControlPlaneEndpointSpec) { +func (in *DockerNodeConfig) DeepCopyInto(out *DockerNodeConfig) { *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ControlPlaneEndpointSpec. -func (in *ControlPlaneEndpointSpec) DeepCopy() *ControlPlaneEndpointSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DockerNodeConfig. +func (in *DockerNodeConfig) DeepCopy() *DockerNodeConfig { if in == nil { return nil } - out := new(ControlPlaneEndpointSpec) + out := new(DockerNodeConfig) in.DeepCopyInto(out) return out } +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *DockerNodeConfig) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *DefaultStorage) DeepCopyInto(out *DefaultStorage) { +func (in *DockerNodeConfigSpec) DeepCopyInto(out *DockerNodeConfigSpec) { *out = *in + if in.Docker != nil { + in, out := &in.Docker, &out.Docker + *out = new(DockerNodeSpec) + (*in).DeepCopyInto(*out) + } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DefaultStorage. -func (in *DefaultStorage) DeepCopy() *DefaultStorage { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DockerNodeConfigSpec. +func (in *DockerNodeConfigSpec) DeepCopy() *DockerNodeConfigSpec { if in == nil { return nil } - out := new(DefaultStorage) + out := new(DockerNodeConfigSpec) in.DeepCopyInto(out) return out } @@ -493,6 +627,32 @@ func (in ExtraAPIServerCertSANs) DeepCopy() ExtraAPIServerCertSANs { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *GenericClusterConfig) DeepCopyInto(out *GenericClusterConfig) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GenericClusterConfig. +func (in *GenericClusterConfig) DeepCopy() *GenericClusterConfig { + if in == nil { + return nil + } + out := new(GenericClusterConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *GenericClusterConfig) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *GenericClusterConfigSpec) DeepCopyInto(out *GenericClusterConfigSpec) { *out = *in if in.KubernetesImageRepository != nil { in, out := &in.KubernetesImageRepository, &out.KubernetesImageRepository @@ -540,27 +700,12 @@ func (in *GenericClusterConfig) DeepCopyInto(out *GenericClusterConfig) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GenericClusterConfig. -func (in *GenericClusterConfig) DeepCopy() *GenericClusterConfig { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GenericClusterConfigSpec. +func (in *GenericClusterConfigSpec) DeepCopy() *GenericClusterConfigSpec { if in == nil { return nil } - out := new(GenericClusterConfig) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *GenericNodeConfig) DeepCopyInto(out *GenericNodeConfig) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GenericNodeConfig. -func (in *GenericNodeConfig) DeepCopy() *GenericNodeConfig { - if in == nil { - return nil - } - out := new(GenericNodeConfig) + out := new(GenericClusterConfigSpec) in.DeepCopyInto(out) return out } @@ -677,25 +822,25 @@ func (in *NFD) DeepCopy() *NFD { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *NodeConfig) DeepCopyInto(out *NodeConfig) { +func (in *NutanixClusterConfig) DeepCopyInto(out *NutanixClusterConfig) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeConfig. -func (in *NodeConfig) DeepCopy() *NodeConfig { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NutanixClusterConfig. +func (in *NutanixClusterConfig) DeepCopy() *NutanixClusterConfig { if in == nil { return nil } - out := new(NodeConfig) + out := new(NutanixClusterConfig) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *NodeConfig) DeepCopyObject() runtime.Object { +func (in *NutanixClusterConfig) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -703,31 +848,27 @@ func (in *NodeConfig) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *NodeConfigSpec) DeepCopyInto(out *NodeConfigSpec) { +func (in *NutanixClusterConfigSpec) DeepCopyInto(out *NutanixClusterConfigSpec) { *out = *in - if in.AWS != nil { - in, out := &in.AWS, &out.AWS - *out = new(AWSNodeSpec) - (*in).DeepCopyInto(*out) - } - if in.Docker != nil { - in, out := &in.Docker, &out.Docker - *out = new(DockerNodeSpec) - (*in).DeepCopyInto(*out) - } if in.Nutanix != nil { in, out := &in.Nutanix, &out.Nutanix - *out = new(NutanixNodeSpec) + *out = new(NutanixSpec) + (*in).DeepCopyInto(*out) + } + in.GenericClusterConfigSpec.DeepCopyInto(&out.GenericClusterConfigSpec) + if in.ControlPlane != nil { + in, out := &in.ControlPlane, &out.ControlPlane + *out = new(NutanixNodeConfigSpec) (*in).DeepCopyInto(*out) } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodeConfigSpec. -func (in *NodeConfigSpec) DeepCopy() *NodeConfigSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NutanixClusterConfigSpec. +func (in *NutanixClusterConfigSpec) DeepCopy() *NutanixClusterConfigSpec { if in == nil { return nil } - out := new(NodeConfigSpec) + out := new(NutanixClusterConfigSpec) in.DeepCopyInto(out) return out } @@ -755,7 +896,7 @@ func (in *NutanixMachineDetails) DeepCopyInto(out *NutanixMachineDetails) { in.Cluster.DeepCopyInto(&out.Cluster) if in.Subnets != nil { in, out := &in.Subnets, &out.Subnets - *out = make([]NutanixResourceIdentifier, len(*in)) + *out = make(NutanixResourceIdentifiers, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -783,6 +924,52 @@ func (in *NutanixMachineDetails) DeepCopy() *NutanixMachineDetails { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NutanixNodeConfig) DeepCopyInto(out *NutanixNodeConfig) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NutanixNodeConfig. +func (in *NutanixNodeConfig) DeepCopy() *NutanixNodeConfig { + if in == nil { + return nil + } + out := new(NutanixNodeConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *NutanixNodeConfig) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NutanixNodeConfigSpec) DeepCopyInto(out *NutanixNodeConfigSpec) { + *out = *in + if in.Nutanix != nil { + in, out := &in.Nutanix, &out.Nutanix + *out = new(NutanixNodeSpec) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NutanixNodeConfigSpec. +func (in *NutanixNodeConfigSpec) DeepCopy() *NutanixNodeConfigSpec { + if in == nil { + return nil + } + out := new(NutanixNodeConfigSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NutanixNodeSpec) DeepCopyInto(out *NutanixNodeSpec) { *out = *in @@ -845,6 +1032,27 @@ func (in *NutanixResourceIdentifier) DeepCopy() *NutanixResourceIdentifier { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in NutanixResourceIdentifiers) DeepCopyInto(out *NutanixResourceIdentifiers) { + { + in := &in + *out = make(NutanixResourceIdentifiers, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NutanixResourceIdentifiers. +func (in NutanixResourceIdentifiers) DeepCopy() NutanixResourceIdentifiers { + if in == nil { + return nil + } + out := new(NutanixResourceIdentifiers) + in.DeepCopyInto(out) + return *out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NutanixSpec) DeepCopyInto(out *NutanixSpec) { *out = *in diff --git a/common/pkg/capi/clustertopology/variables/fromcrdyaml.go b/common/pkg/capi/clustertopology/variables/fromcrdyaml.go new file mode 100644 index 000000000..f04c50c13 --- /dev/null +++ b/common/pkg/capi/clustertopology/variables/fromcrdyaml.go @@ -0,0 +1,161 @@ +// Copyright 2024 D2iQ, Inc. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +package variables + +import ( + "fmt" + + apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/serializer" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + "k8s.io/apimachinery/pkg/util/validation/field" + "k8s.io/utils/ptr" + clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" +) + +func MustSchemaFromCRDYAML(yaml []byte) clusterv1.VariableSchema { + schema, err := SchemaFromCRDYAML(yaml) + if err != nil { + panic(err) + } + return schema +} + +func SchemaFromCRDYAML(yaml []byte) (clusterv1.VariableSchema, error) { + sch := runtime.NewScheme() + utilruntime.Must(apiextensionsv1.AddToScheme(sch)) + decode := serializer.NewCodecFactory(sch).UniversalDeserializer().Decode + obj, gKV, _ := decode(yaml, nil, nil) + if gKV.Kind != "CustomResourceDefinition" { + return clusterv1.VariableSchema{}, fmt.Errorf( + "expected CustomResourceDefinition, got %s", + gKV.Kind, + ) + } + crd := obj.(*apiextensionsv1.CustomResourceDefinition) + if len(crd.Spec.Versions) != 1 { + return clusterv1.VariableSchema{}, fmt.Errorf( + "expected exactly one version, got %d", + len(crd.Spec.Versions), + ) + } + if crd.Spec.Versions[0].Schema.OpenAPIV3Schema == nil { + return clusterv1.VariableSchema{}, fmt.Errorf("expected OpenAPIV3Schema, got nil") + } + + spec, ok := crd.Spec.Versions[0].Schema.OpenAPIV3Schema.Properties["spec"] + if !ok { + return clusterv1.VariableSchema{}, fmt.Errorf("missing spec") + } + + jsonSchemaProps, err := ConvertAPIExtensionsToJSONSchemaProps( + &spec, field.NewPath(""), + ) + if err != nil { + return clusterv1.VariableSchema{}, fmt.Errorf( + "failed to parse CRD into variables schema: %w", + err.ToAggregate(), + ) + } + + return clusterv1.VariableSchema{ + OpenAPIV3Schema: *jsonSchemaProps, + }, nil +} + +// ConvertAPIExtensionsToJSONSchemaProps converts a apiextensions.JSONSchemaProp to clusterv1.JSONSchemaProps. +func ConvertAPIExtensionsToJSONSchemaProps( + schema *apiextensionsv1.JSONSchemaProps, fldPath *field.Path, +) (*clusterv1.JSONSchemaProps, field.ErrorList) { + var allErrs field.ErrorList + + props := &clusterv1.JSONSchemaProps{ + Type: schema.Type, + Required: schema.Required, + MaxItems: schema.MaxItems, + MinItems: schema.MinItems, + UniqueItems: schema.UniqueItems, + Format: schema.Format, + MaxLength: schema.MaxLength, + MinLength: schema.MinLength, + Pattern: schema.Pattern, + ExclusiveMaximum: schema.ExclusiveMaximum, + ExclusiveMinimum: schema.ExclusiveMinimum, + XPreserveUnknownFields: ptr.Deref(schema.XPreserveUnknownFields, false), + Default: schema.Default, + Enum: schema.Enum, + Example: schema.Example, + } + + if schema.Maximum != nil { + props.Maximum = ptr.To(int64(*schema.Maximum)) + } + + if schema.Minimum != nil { + props.Minimum = ptr.To(int64(*schema.Minimum)) + } + + if schema.AdditionalProperties != nil && schema.AdditionalProperties.Schema != nil { + jsonSchemaProps, err := ConvertAPIExtensionsToJSONSchemaProps( + schema.AdditionalProperties.Schema, fldPath.Child("additionalProperties"), + ) + if err != nil { + allErrs = append( + allErrs, + field.Invalid( + fldPath.Child("additionalProperties"), + "", + fmt.Sprintf("failed to convert schema: %v", err), + ), + ) + } else { + props.AdditionalProperties = jsonSchemaProps + } + } + + if len(schema.Properties) > 0 { + props.Properties = make(map[string]clusterv1.JSONSchemaProps, len(schema.Properties)) + for propertyName := range schema.Properties { + p := schema.Properties[propertyName] + apiExtensionsSchema, err := ConvertAPIExtensionsToJSONSchemaProps( + &p, + fldPath.Child("properties").Key(propertyName), + ) + if err != nil { + allErrs = append( + allErrs, + field.Invalid( + fldPath.Child("properties").Key(propertyName), + "", + fmt.Sprintf("failed to convert schema: %v", err), + ), + ) + } else { + props.Properties[propertyName] = *apiExtensionsSchema + } + } + } + + if schema.Items != nil && schema.Items.Schema != nil { + jsonPropsSchema, err := ConvertAPIExtensionsToJSONSchemaProps( + schema.Items.Schema, + fldPath.Child("items"), + ) + if err != nil { + allErrs = append( + allErrs, + field.Invalid( + fldPath.Child("items"), + "", + fmt.Sprintf("failed to convert schema: %v", err), + ), + ) + } else { + props.Items = jsonPropsSchema + } + } + + return props, allErrs +} diff --git a/common/pkg/testutils/openapi/convert.go b/common/pkg/testutils/openapi/convert.go index 5eb248617..9e08c0e50 100644 --- a/common/pkg/testutils/openapi/convert.go +++ b/common/pkg/testutils/openapi/convert.go @@ -14,12 +14,12 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" ) -// ConvertToAPIExtensionsJSONSchemaProps converts a clusterv1.JSONSchemaProps to apiextensions.JSONSchemaProp. +// ConvertJSONSchemaPropsToAPIExtensions converts a clusterv1.JSONSchemaProps to apiextensions.JSONSchemaProp. // NOTE: This is used whenever we want to use one of the upstream libraries, as they use apiextensions.JSONSchemaProp. // NOTE: If new fields are added to clusterv1.JSONSchemaProps (e.g. to support complex types), the corresponding // schema validation must be added to validateRootSchema too. // See: https://github.com/kubernetes-sigs/cluster-api/blob/v1.5.1/internal/topology/variables/schema.go#L35 -func ConvertToAPIExtensionsJSONSchemaProps( +func ConvertJSONSchemaPropsToAPIExtensions( schema *clusterv1.JSONSchemaProps, fldPath *field.Path, ) (*apiextensions.JSONSchemaProps, field.ErrorList) { var allErrs field.ErrorList @@ -142,7 +142,7 @@ func ConvertToAPIExtensionsJSONSchemaProps( } if schema.AdditionalProperties != nil { - apiExtensionsSchema, err := ConvertToAPIExtensionsJSONSchemaProps( + apiExtensionsSchema, err := ConvertJSONSchemaPropsToAPIExtensions( schema.AdditionalProperties, fldPath.Child("additionalProperties"), ) if err != nil { @@ -168,7 +168,7 @@ func ConvertToAPIExtensionsJSONSchemaProps( props.Properties = map[string]apiextensions.JSONSchemaProps{} for propertyName := range schema.Properties { p := schema.Properties[propertyName] - apiExtensionsSchema, err := ConvertToAPIExtensionsJSONSchemaProps( + apiExtensionsSchema, err := ConvertJSONSchemaPropsToAPIExtensions( &p, fldPath.Child("properties").Key(propertyName), ) @@ -188,7 +188,7 @@ func ConvertToAPIExtensionsJSONSchemaProps( } if schema.Items != nil { - apiExtensionsSchema, err := ConvertToAPIExtensionsJSONSchemaProps( + apiExtensionsSchema, err := ConvertJSONSchemaPropsToAPIExtensions( schema.Items, fldPath.Child("items"), ) diff --git a/common/pkg/testutils/openapi/validate.go b/common/pkg/testutils/openapi/validate.go index bf776db6d..b42dbe8ee 100644 --- a/common/pkg/testutils/openapi/validate.go +++ b/common/pkg/testutils/openapi/validate.go @@ -38,7 +38,7 @@ func ValidateClusterVariable( } // Convert schema to Kubernetes APIExtensions Schema. - apiExtensionsSchema, allErrs := ConvertToAPIExtensionsJSONSchemaProps( + apiExtensionsSchema, allErrs := ConvertJSONSchemaPropsToAPIExtensions( &definition.Schema.OpenAPIV3Schema, field.NewPath("schema"), ) if len(allErrs) > 0 { diff --git a/go.mod b/go.mod index d0e79aec2..3621a941f 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/go-logr/logr v1.4.1 github.com/google/go-cmp v0.6.0 github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api v0.0.0-00010101000000-000000000000 - github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common v0.0.0-00010101000000-000000000000 + github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common v0.7.0 github.com/nutanix-cloud-native/prism-go-client v0.3.4 github.com/onsi/ginkgo/v2 v2.17.1 github.com/onsi/gomega v1.33.0 diff --git a/pkg/common/clusterconfig/types.go b/pkg/common/clusterconfig/types.go new file mode 100644 index 000000000..c82df26c6 --- /dev/null +++ b/pkg/common/clusterconfig/types.go @@ -0,0 +1,16 @@ +// Copyright 2024 D2iQ, Inc. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +package clusterconfig + +import carenv1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" + +type ClusterConfig struct { + AWS *carenv1.AWSSpec `json:"aws,omitempty"` + + Docker *carenv1.AWSSpec `json:"doker,omitempty"` + + Nutanix *carenv1.NutanixSpec `json:"nutanix,omitempty"` + + carenv1.GenericClusterConfigSpec `json:",inline"` +} diff --git a/pkg/handlers/aws/clusterconfig/variables.go b/pkg/handlers/aws/clusterconfig/variables.go index e80b72282..2b455d816 100644 --- a/pkg/handlers/aws/clusterconfig/variables.go +++ b/pkg/handlers/aws/clusterconfig/variables.go @@ -43,7 +43,7 @@ func (h *awsClusterConfigVariableHandler) DiscoverVariables( resp.Variables = append(resp.Variables, clusterv1.ClusterClassVariable{ Name: clusterconfig.MetaVariableName, Required: true, - Schema: v1alpha1.NewAWSClusterConfigSpec().VariableSchema(), + Schema: v1alpha1.AWSClusterConfig{}.VariableSchema(), }) resp.SetStatus(runtimehooksv1.ResponseStatusSuccess) } diff --git a/pkg/handlers/aws/mutation/ami/variables_test.go b/pkg/handlers/aws/mutation/ami/variables_test.go index 63eb78802..ed6392086 100644 --- a/pkg/handlers/aws/mutation/ami/variables_test.go +++ b/pkg/handlers/aws/mutation/ami/variables_test.go @@ -18,13 +18,13 @@ func TestVariableValidation(t *testing.T) { capitest.ValidateDiscoverVariables( t, clusterconfig.MetaVariableName, - ptr.To(v1alpha1.NewAWSClusterConfigSpec().VariableSchema()), + ptr.To(v1alpha1.AWSClusterConfig{}.VariableSchema()), true, awsclusterconfig.NewVariable, capitest.VariableTestDef{ Name: "AMI specification", - Vals: v1alpha1.ClusterConfigSpec{ - ControlPlane: &v1alpha1.NodeConfigSpec{ + Vals: v1alpha1.AWSClusterConfigSpec{ + ControlPlane: &v1alpha1.AWSNodeConfigSpec{ AWS: &v1alpha1.AWSNodeSpec{ AMISpec: &v1alpha1.AMISpec{ ID: "ami-1234", diff --git a/pkg/handlers/aws/mutation/controlplaneloadbalancer/variables_test.go b/pkg/handlers/aws/mutation/controlplaneloadbalancer/variables_test.go index 059f4f0ed..bf05693e1 100644 --- a/pkg/handlers/aws/mutation/controlplaneloadbalancer/variables_test.go +++ b/pkg/handlers/aws/mutation/controlplaneloadbalancer/variables_test.go @@ -19,12 +19,12 @@ func TestVariableValidation(t *testing.T) { capitest.ValidateDiscoverVariables( t, clusterconfig.MetaVariableName, - ptr.To(v1alpha1.NewAWSClusterConfigSpec().VariableSchema()), + ptr.To(v1alpha1.AWSClusterConfig{}.VariableSchema()), true, awsclusterconfig.NewVariable, capitest.VariableTestDef{ Name: "specified internet-facing scheme", - Vals: v1alpha1.ClusterConfigSpec{ + Vals: v1alpha1.AWSClusterConfigSpec{ AWS: &v1alpha1.AWSSpec{ ControlPlaneLoadBalancer: &v1alpha1.AWSLoadBalancerSpec{ Scheme: &capav1.ELBSchemeInternetFacing, @@ -34,7 +34,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "specified internal scheme", - Vals: v1alpha1.ClusterConfigSpec{ + Vals: v1alpha1.AWSClusterConfigSpec{ AWS: &v1alpha1.AWSSpec{ ControlPlaneLoadBalancer: &v1alpha1.AWSLoadBalancerSpec{ Scheme: &capav1.ELBSchemeInternal, @@ -44,7 +44,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "specified invalid scheme", - Vals: v1alpha1.ClusterConfigSpec{ + Vals: v1alpha1.AWSClusterConfigSpec{ AWS: &v1alpha1.AWSSpec{ ControlPlaneLoadBalancer: &v1alpha1.AWSLoadBalancerSpec{ Scheme: ptr.To(capav1.ELBScheme("invalid")), diff --git a/pkg/handlers/aws/mutation/iaminstanceprofile/variables_test.go b/pkg/handlers/aws/mutation/iaminstanceprofile/variables_test.go index f5aea0919..41afe0e97 100644 --- a/pkg/handlers/aws/mutation/iaminstanceprofile/variables_test.go +++ b/pkg/handlers/aws/mutation/iaminstanceprofile/variables_test.go @@ -18,13 +18,13 @@ func TestVariableValidation(t *testing.T) { capitest.ValidateDiscoverVariables( t, clusterconfig.MetaVariableName, - ptr.To(v1alpha1.NewAWSClusterConfigSpec().VariableSchema()), + ptr.To(v1alpha1.AWSClusterConfig{}.VariableSchema()), true, awsclusterconfig.NewVariable, capitest.VariableTestDef{ Name: "AMI specification", - Vals: v1alpha1.ClusterConfigSpec{ - ControlPlane: &v1alpha1.NodeConfigSpec{ + Vals: v1alpha1.AWSClusterConfigSpec{ + ControlPlane: &v1alpha1.AWSNodeConfigSpec{ AWS: &v1alpha1.AWSNodeSpec{ AMISpec: &v1alpha1.AMISpec{ ID: "ami-1234", diff --git a/pkg/handlers/aws/mutation/instancetype/variables_test.go b/pkg/handlers/aws/mutation/instancetype/variables_test.go index 040ca4384..a91e10294 100644 --- a/pkg/handlers/aws/mutation/instancetype/variables_test.go +++ b/pkg/handlers/aws/mutation/instancetype/variables_test.go @@ -18,13 +18,13 @@ func TestVariableValidation(t *testing.T) { capitest.ValidateDiscoverVariables( t, clusterconfig.MetaVariableName, - ptr.To(v1alpha1.NewAWSClusterConfigSpec().VariableSchema()), + ptr.To(v1alpha1.AWSClusterConfig{}.VariableSchema()), true, awsclusterconfig.NewVariable, capitest.VariableTestDef{ Name: "specified instance type", - Vals: v1alpha1.ClusterConfigSpec{ - ControlPlane: &v1alpha1.NodeConfigSpec{ + Vals: v1alpha1.AWSClusterConfigSpec{ + ControlPlane: &v1alpha1.AWSNodeConfigSpec{ AWS: &v1alpha1.AWSNodeSpec{ InstanceType: ptr.To(v1alpha1.InstanceType("m5.small")), }, diff --git a/pkg/handlers/aws/mutation/network/variables_test.go b/pkg/handlers/aws/mutation/network/variables_test.go index 2aa82b7a2..127045b48 100644 --- a/pkg/handlers/aws/mutation/network/variables_test.go +++ b/pkg/handlers/aws/mutation/network/variables_test.go @@ -18,12 +18,12 @@ func TestVariableValidation(t *testing.T) { capitest.ValidateDiscoverVariables( t, clusterconfig.MetaVariableName, - ptr.To(v1alpha1.NewAWSClusterConfigSpec().VariableSchema()), + ptr.To(v1alpha1.AWSClusterConfig{}.VariableSchema()), true, awsclusterconfig.NewVariable, capitest.VariableTestDef{ Name: "specified VPC ID", - Vals: v1alpha1.ClusterConfigSpec{ + Vals: v1alpha1.AWSClusterConfigSpec{ AWS: &v1alpha1.AWSSpec{ Network: &v1alpha1.AWSNetwork{ VPC: &v1alpha1.VPC{ @@ -35,7 +35,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "specified subnet IDs", - Vals: v1alpha1.ClusterConfigSpec{ + Vals: v1alpha1.AWSClusterConfigSpec{ AWS: &v1alpha1.AWSSpec{ Network: &v1alpha1.AWSNetwork{ Subnets: v1alpha1.Subnets{ @@ -49,7 +49,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "specified both VPC ID and subnet IDs", - Vals: v1alpha1.ClusterConfigSpec{ + Vals: v1alpha1.AWSClusterConfigSpec{ AWS: &v1alpha1.AWSSpec{ Network: &v1alpha1.AWSNetwork{ VPC: &v1alpha1.VPC{ diff --git a/pkg/handlers/aws/mutation/region/variables_test.go b/pkg/handlers/aws/mutation/region/variables_test.go index 295fb3f12..112108231 100644 --- a/pkg/handlers/aws/mutation/region/variables_test.go +++ b/pkg/handlers/aws/mutation/region/variables_test.go @@ -18,12 +18,12 @@ func TestVariableValidation(t *testing.T) { capitest.ValidateDiscoverVariables( t, clusterconfig.MetaVariableName, - ptr.To(v1alpha1.NewAWSClusterConfigSpec().VariableSchema()), + ptr.To(v1alpha1.AWSClusterConfig{}.VariableSchema()), true, awsclusterconfig.NewVariable, capitest.VariableTestDef{ Name: "specified region", - Vals: v1alpha1.ClusterConfigSpec{ + Vals: v1alpha1.AWSClusterConfigSpec{ AWS: &v1alpha1.AWSSpec{ Region: ptr.To(v1alpha1.Region("a-specified-region")), }, diff --git a/pkg/handlers/aws/mutation/securitygroups/variables_test.go b/pkg/handlers/aws/mutation/securitygroups/variables_test.go index 27e634de3..b7e3646a3 100644 --- a/pkg/handlers/aws/mutation/securitygroups/variables_test.go +++ b/pkg/handlers/aws/mutation/securitygroups/variables_test.go @@ -18,13 +18,13 @@ func TestVariableValidation(t *testing.T) { capitest.ValidateDiscoverVariables( t, clusterconfig.MetaVariableName, - ptr.To(v1alpha1.NewAWSClusterConfigSpec().VariableSchema()), + ptr.To(v1alpha1.AWSClusterConfig{}.VariableSchema()), true, awsclusterconfig.NewVariable, capitest.VariableTestDef{ Name: "Additional Security Group Specification", - Vals: v1alpha1.ClusterConfigSpec{ - ControlPlane: &v1alpha1.NodeConfigSpec{ + Vals: v1alpha1.AWSClusterConfigSpec{ + ControlPlane: &v1alpha1.AWSNodeConfigSpec{ AWS: &v1alpha1.AWSNodeSpec{ AdditionalSecurityGroups: v1alpha1.AdditionalSecurityGroup{ { diff --git a/pkg/handlers/aws/workerconfig/variables.go b/pkg/handlers/aws/workerconfig/variables.go index 3b0975211..bedcc34f4 100644 --- a/pkg/handlers/aws/workerconfig/variables.go +++ b/pkg/handlers/aws/workerconfig/variables.go @@ -43,7 +43,7 @@ func (h *awsWorkerConfigVariableHandler) DiscoverVariables( resp.Variables = append(resp.Variables, clusterv1.ClusterClassVariable{ Name: workerconfig.MetaVariableName, Required: false, - Schema: v1alpha1.NewAWSWorkerConfigSpec().VariableSchema(), + Schema: v1alpha1.AWSNodeConfig{}.VariableSchema(), }) resp.SetStatus(runtimehooksv1.ResponseStatusSuccess) } diff --git a/pkg/handlers/aws/workerconfig/variables_test.go b/pkg/handlers/aws/workerconfig/variables_test.go index 8bd661665..4577e85a5 100644 --- a/pkg/handlers/aws/workerconfig/variables_test.go +++ b/pkg/handlers/aws/workerconfig/variables_test.go @@ -17,12 +17,12 @@ func TestVariableValidation(t *testing.T) { capitest.ValidateDiscoverVariables( t, workerconfig.MetaVariableName, - ptr.To(v1alpha1.NewAWSWorkerConfigSpec().VariableSchema()), + ptr.To(v1alpha1.AWSNodeConfig{}.VariableSchema()), false, NewVariable, capitest.VariableTestDef{ Name: "specified IAM instance profile", - Vals: v1alpha1.NodeConfigSpec{ + Vals: v1alpha1.AWSNodeConfigSpec{ AWS: &v1alpha1.AWSNodeSpec{ IAMInstanceProfile: ptr.To( v1alpha1.IAMInstanceProfile("nodes.cluster-api-provider-aws.sigs.k8s.io"), @@ -32,7 +32,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "specified instance type", - Vals: v1alpha1.NodeConfigSpec{ + Vals: v1alpha1.AWSNodeConfigSpec{ AWS: &v1alpha1.AWSNodeSpec{InstanceType: ptr.To(v1alpha1.InstanceType("m5.small"))}, }, }, diff --git a/pkg/handlers/docker/clusterconfig/variables.go b/pkg/handlers/docker/clusterconfig/variables.go index 27d9b1dea..6fccf3679 100644 --- a/pkg/handlers/docker/clusterconfig/variables.go +++ b/pkg/handlers/docker/clusterconfig/variables.go @@ -46,7 +46,7 @@ func (h *dockerClusterConfigVariableHandler) DiscoverVariables( resp.Variables = append(resp.Variables, clusterv1.ClusterClassVariable{ Name: clusterconfig.MetaVariableName, Required: true, - Schema: v1alpha1.ClusterConfigSpec{Docker: &v1alpha1.DockerSpec{}}.VariableSchema(), + Schema: v1alpha1.DockerClusterConfig{}.VariableSchema(), }) resp.SetStatus(runtimehooksv1.ResponseStatusSuccess) } diff --git a/pkg/handlers/docker/mutation/customimage/variables_test.go b/pkg/handlers/docker/mutation/customimage/variables_test.go index 9840b41ac..e965d9f68 100644 --- a/pkg/handlers/docker/mutation/customimage/variables_test.go +++ b/pkg/handlers/docker/mutation/customimage/variables_test.go @@ -18,13 +18,13 @@ func TestVariableValidation(t *testing.T) { capitest.ValidateDiscoverVariables( t, clusterconfig.MetaVariableName, - ptr.To(v1alpha1.ClusterConfigSpec{Docker: &v1alpha1.DockerSpec{}}.VariableSchema()), + ptr.To(v1alpha1.DockerClusterConfig{}.VariableSchema()), true, dockerclusterconfig.NewVariable, capitest.VariableTestDef{ Name: "valid", - Vals: v1alpha1.ClusterConfigSpec{ - ControlPlane: &v1alpha1.NodeConfigSpec{ + Vals: v1alpha1.DockerClusterConfigSpec{ + ControlPlane: &v1alpha1.DockerNodeConfigSpec{ Docker: &v1alpha1.DockerNodeSpec{ CustomImage: ptr.To(v1alpha1.OCIImage("docker.io/some/image:v2.3.4")), }, @@ -33,8 +33,8 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "invalid", - Vals: v1alpha1.ClusterConfigSpec{ - ControlPlane: &v1alpha1.NodeConfigSpec{ + Vals: v1alpha1.DockerClusterConfigSpec{ + ControlPlane: &v1alpha1.DockerNodeConfigSpec{ Docker: &v1alpha1.DockerNodeSpec{ CustomImage: ptr.To(v1alpha1.OCIImage("this.is.not.valid?")), }, diff --git a/pkg/handlers/docker/workerconfig/variables.go b/pkg/handlers/docker/workerconfig/variables.go index c9f3e8457..fe3e2ef0d 100644 --- a/pkg/handlers/docker/workerconfig/variables.go +++ b/pkg/handlers/docker/workerconfig/variables.go @@ -46,7 +46,7 @@ func (h *dockerWorkerConfigVariableHandler) DiscoverVariables( resp.Variables = append(resp.Variables, clusterv1.ClusterClassVariable{ Name: workerconfig.MetaVariableName, Required: false, - Schema: v1alpha1.NodeConfigSpec{Docker: &v1alpha1.DockerNodeSpec{}}.VariableSchema(), + Schema: v1alpha1.DockerNodeConfig{}.VariableSchema(), }) resp.SetStatus(runtimehooksv1.ResponseStatusSuccess) } diff --git a/pkg/handlers/docker/workerconfig/variables_test.go b/pkg/handlers/docker/workerconfig/variables_test.go index 09a334706..7a67b9395 100644 --- a/pkg/handlers/docker/workerconfig/variables_test.go +++ b/pkg/handlers/docker/workerconfig/variables_test.go @@ -17,7 +17,7 @@ func TestVariableValidation(t *testing.T) { capitest.ValidateDiscoverVariables( t, workerconfig.MetaVariableName, - ptr.To(v1alpha1.NodeConfigSpec{Docker: &v1alpha1.DockerNodeSpec{}}.VariableSchema()), + ptr.To(v1alpha1.DockerNodeConfig{}.VariableSchema()), false, NewVariable, ) diff --git a/pkg/handlers/generic/clusterconfig/variables_test.go b/pkg/handlers/generic/clusterconfig/variables_test.go index 70a691453..8c7639911 100644 --- a/pkg/handlers/generic/clusterconfig/variables_test.go +++ b/pkg/handlers/generic/clusterconfig/variables_test.go @@ -21,7 +21,7 @@ func TestVariableValidation(t *testing.T) { NewVariable, capitest.VariableTestDef{ Name: "valid config", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ Proxy: &v1alpha1.HTTPProxy{ HTTP: "http://a.b.c.example.com", HTTPS: "https://a.b.c.example.com", diff --git a/pkg/handlers/generic/lifecycle/ccm/aws/handler.go b/pkg/handlers/generic/lifecycle/ccm/aws/handler.go index f67f36148..45543edce 100644 --- a/pkg/handlers/generic/lifecycle/ccm/aws/handler.go +++ b/pkg/handlers/generic/lifecycle/ccm/aws/handler.go @@ -15,8 +15,8 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" ctrlclient "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/k8s/client" + commonclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/common/clusterconfig" lifecycleutils "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/utils" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/options" ) @@ -57,7 +57,7 @@ func New( func (a *AWSCCM) Apply( ctx context.Context, cluster *clusterv1.Cluster, - _ *v1alpha1.ClusterConfigSpec, + _ *commonclusterconfig.ClusterConfig, log logr.Logger, ) error { log.Info("Creating AWS CCM ConfigMap for Cluster") diff --git a/pkg/handlers/generic/lifecycle/ccm/handler.go b/pkg/handlers/generic/lifecycle/ccm/handler.go index ef240ee8f..1403e319a 100644 --- a/pkg/handlers/generic/lifecycle/ccm/handler.go +++ b/pkg/handlers/generic/lifecycle/ccm/handler.go @@ -18,6 +18,7 @@ import ( commonhandlers "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/lifecycle" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/variables" + commonclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/common/clusterconfig" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig" ) @@ -29,7 +30,7 @@ type CCMProvider interface { Apply( context.Context, *clusterv1.Cluster, - *v1alpha1.ClusterConfigSpec, + *commonclusterconfig.ClusterConfig, logr.Logger, ) error } @@ -95,7 +96,7 @@ func (c *CCMHandler) AfterControlPlaneInitialized( return } - clusterConfigVar, err := variables.Get[v1alpha1.ClusterConfigSpec]( + clusterConfigVar, err := variables.Get[commonclusterconfig.ClusterConfig]( varMap, clusterconfig.MetaVariableName, ) diff --git a/pkg/handlers/generic/lifecycle/ccm/nutanix/handler.go b/pkg/handlers/generic/lifecycle/ccm/nutanix/handler.go index 610468fc5..9e0d90345 100644 --- a/pkg/handlers/generic/lifecycle/ccm/nutanix/handler.go +++ b/pkg/handlers/generic/lifecycle/ccm/nutanix/handler.go @@ -18,8 +18,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" caaphv1 "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/external/sigs.k8s.io/cluster-api-addon-provider-helm/api/v1alpha1" - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/k8s/client" + commonclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/common/clusterconfig" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/config" lifecycleutils "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/lifecycle/utils" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/options" @@ -72,7 +72,7 @@ func New( func (p *provider) Apply( ctx context.Context, cluster *clusterv1.Cluster, - clusterConfig *v1alpha1.ClusterConfigSpec, + clusterConfig *commonclusterconfig.ClusterConfig, log logr.Logger, ) error { // No need to check for nil values in the struct, this function will only be called if CCM is not nil @@ -164,7 +164,7 @@ func (p *provider) Apply( return nil } -func templateValues(clusterConfig *v1alpha1.ClusterConfigSpec, text string) (string, error) { +func templateValues(clusterConfig *commonclusterconfig.ClusterConfig, text string) (string, error) { helmValuesTemplate, err := template.New("").Parse(text) if err != nil { return "", fmt.Errorf("failed to parse Helm values template: %w", err) diff --git a/pkg/handlers/generic/lifecycle/ccm/nutanix/handler_test.go b/pkg/handlers/generic/lifecycle/ccm/nutanix/handler_test.go index 2a9d71322..933b66184 100644 --- a/pkg/handlers/generic/lifecycle/ccm/nutanix/handler_test.go +++ b/pkg/handlers/generic/lifecycle/ccm/nutanix/handler_test.go @@ -13,6 +13,7 @@ import ( "k8s.io/utils/ptr" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" + commonclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/common/clusterconfig" ) const ( @@ -60,14 +61,15 @@ func Test_templateValues(t *testing.T) { tests := []struct { name string - clusterConfig *v1alpha1.ClusterConfigSpec - in string - expected string + clusterConfig *commonclusterconfig.ClusterConfig + + in string + expected string }{ { name: "With AdditionalTrustBundle set", - clusterConfig: &v1alpha1.ClusterConfigSpec{ - GenericClusterConfig: v1alpha1.GenericClusterConfig{ + clusterConfig: &commonclusterconfig.ClusterConfig{ + GenericClusterConfigSpec: v1alpha1.GenericClusterConfigSpec{ Addons: &v1alpha1.Addons{ CCM: &v1alpha1.CCM{ Credentials: &corev1.LocalObjectReference{ @@ -91,8 +93,8 @@ func Test_templateValues(t *testing.T) { }, { name: "Without an AdditionalTrustBundle set", - clusterConfig: &v1alpha1.ClusterConfigSpec{ - GenericClusterConfig: v1alpha1.GenericClusterConfig{ + clusterConfig: &commonclusterconfig.ClusterConfig{ + GenericClusterConfigSpec: v1alpha1.GenericClusterConfigSpec{ Addons: &v1alpha1.Addons{ CCM: &v1alpha1.CCM{ Credentials: &corev1.LocalObjectReference{ diff --git a/pkg/handlers/generic/lifecycle/clusterautoscaler/variables_test.go b/pkg/handlers/generic/lifecycle/clusterautoscaler/variables_test.go index 81ad72479..3cd33c059 100644 --- a/pkg/handlers/generic/lifecycle/clusterautoscaler/variables_test.go +++ b/pkg/handlers/generic/lifecycle/clusterautoscaler/variables_test.go @@ -22,7 +22,7 @@ func TestVariableValidation(t *testing.T) { clusterconfig.NewVariable, capitest.VariableTestDef{ Name: "ClusterResourceSet strategy", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ Addons: &v1alpha1.Addons{ ClusterAutoscaler: &v1alpha1.ClusterAutoscaler{ Strategy: v1alpha1.AddonStrategyClusterResourceSet, @@ -32,7 +32,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "HelmAddon strategy", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ Addons: &v1alpha1.Addons{ ClusterAutoscaler: &v1alpha1.ClusterAutoscaler{ Strategy: v1alpha1.AddonStrategyHelmAddon, @@ -42,7 +42,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "invalid strategy", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ Addons: &v1alpha1.Addons{ ClusterAutoscaler: &v1alpha1.ClusterAutoscaler{ Strategy: "invalid-strategy", diff --git a/pkg/handlers/generic/lifecycle/cni/variables_test.go b/pkg/handlers/generic/lifecycle/cni/variables_test.go index 0023a9b17..9c6e515e7 100644 --- a/pkg/handlers/generic/lifecycle/cni/variables_test.go +++ b/pkg/handlers/generic/lifecycle/cni/variables_test.go @@ -22,7 +22,7 @@ func TestVariableValidation(t *testing.T) { clusterconfig.NewVariable, capitest.VariableTestDef{ Name: "set with valid provider using ClusterResourceSet strategy", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ Addons: &v1alpha1.Addons{ CNI: &v1alpha1.CNI{ Provider: v1alpha1.CNIProviderCalico, @@ -33,7 +33,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "set with valid provider using HelmAddon strategy", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ Addons: &v1alpha1.Addons{ CNI: &v1alpha1.CNI{ Provider: v1alpha1.CNIProviderCalico, @@ -44,7 +44,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "set with invalid provider", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ Addons: &v1alpha1.Addons{ CNI: &v1alpha1.CNI{ Provider: "invalid-provider", @@ -56,7 +56,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "set with invalid strategy", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ Addons: &v1alpha1.Addons{ CNI: &v1alpha1.CNI{ Provider: v1alpha1.CNIProviderCalico, diff --git a/pkg/handlers/generic/lifecycle/nfd/variables_test.go b/pkg/handlers/generic/lifecycle/nfd/variables_test.go index 110a57bbf..b615e4c92 100644 --- a/pkg/handlers/generic/lifecycle/nfd/variables_test.go +++ b/pkg/handlers/generic/lifecycle/nfd/variables_test.go @@ -22,7 +22,7 @@ func TestVariableValidation(t *testing.T) { clusterconfig.NewVariable, capitest.VariableTestDef{ Name: "ClusterResourceSet strategy", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ Addons: &v1alpha1.Addons{ NFD: &v1alpha1.NFD{ Strategy: v1alpha1.AddonStrategyClusterResourceSet, @@ -32,7 +32,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "HelmAddon strategy", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ Addons: &v1alpha1.Addons{ NFD: &v1alpha1.NFD{ Strategy: v1alpha1.AddonStrategyHelmAddon, @@ -42,7 +42,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "invalid strategy", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ Addons: &v1alpha1.Addons{ NFD: &v1alpha1.NFD{ Strategy: "invalid-strategy", diff --git a/pkg/handlers/generic/mutation/etcd/variables_test.go b/pkg/handlers/generic/mutation/etcd/variables_test.go index f2488140a..143451ac4 100644 --- a/pkg/handlers/generic/mutation/etcd/variables_test.go +++ b/pkg/handlers/generic/mutation/etcd/variables_test.go @@ -22,13 +22,13 @@ func TestVariableValidation(t *testing.T) { clusterconfig.NewVariable, capitest.VariableTestDef{ Name: "unset", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ Etcd: &v1alpha1.Etcd{}, }, }, capitest.VariableTestDef{ Name: "set with valid image values", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ Etcd: &v1alpha1.Etcd{ Image: &v1alpha1.Image{ Repository: "my-registry.io/my-org/my-repo", @@ -39,7 +39,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "set with invalid image repository", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ Etcd: &v1alpha1.Etcd{ Image: &v1alpha1.Image{ Repository: "https://this.should.not.have.a.scheme", @@ -50,7 +50,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "set with invalid image tag", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ Etcd: &v1alpha1.Etcd{ Image: &v1alpha1.Image{ Tag: "this:is:not:a:valid:tag", diff --git a/pkg/handlers/generic/mutation/extraapiservercertsans/inject_test.go b/pkg/handlers/generic/mutation/extraapiservercertsans/inject_test.go index 19a4d447e..2204cb59d 100644 --- a/pkg/handlers/generic/mutation/extraapiservercertsans/inject_test.go +++ b/pkg/handlers/generic/mutation/extraapiservercertsans/inject_test.go @@ -51,8 +51,8 @@ var _ = Describe("Generate Extra API server certificate patches", func() { Vars: []runtimehooksv1.Variable{ capitest.VariableWithValue( clusterconfig.MetaVariableName, - v1alpha1.ClusterConfigSpec{ - GenericClusterConfig: v1alpha1.GenericClusterConfig{ + v1alpha1.AWSClusterConfigSpec{ + GenericClusterConfigSpec: v1alpha1.GenericClusterConfigSpec{ ExtraAPIServerCertSANs: v1alpha1.ExtraAPIServerCertSANs{ "a.b.c.example.com", "a.b.c.example.com", @@ -92,11 +92,9 @@ var _ = Describe("Generate Extra API server certificate patches", func() { Vars: []runtimehooksv1.Variable{ capitest.VariableWithValue( clusterconfig.MetaVariableName, - v1alpha1.ClusterConfigSpec{ - GenericClusterConfig: v1alpha1.GenericClusterConfig{ - ExtraAPIServerCertSANs: v1alpha1.ExtraAPIServerCertSANs{ - "a.b.c.example.com", - }, + v1alpha1.GenericClusterConfigSpec{ + ExtraAPIServerCertSANs: v1alpha1.ExtraAPIServerCertSANs{ + "a.b.c.example.com", }, }, ), @@ -136,11 +134,9 @@ var _ = Describe("Generate Extra API server certificate patches", func() { Vars: []runtimehooksv1.Variable{ capitest.VariableWithValue( clusterconfig.MetaVariableName, - v1alpha1.ClusterConfigSpec{ - GenericClusterConfig: v1alpha1.GenericClusterConfig{ - ExtraAPIServerCertSANs: v1alpha1.ExtraAPIServerCertSANs{ - "a.b.c.example.com", - }, + v1alpha1.GenericClusterConfigSpec{ + ExtraAPIServerCertSANs: v1alpha1.ExtraAPIServerCertSANs{ + "a.b.c.example.com", }, }, ), diff --git a/pkg/handlers/generic/mutation/extraapiservercertsans/variables_test.go b/pkg/handlers/generic/mutation/extraapiservercertsans/variables_test.go index f6925b313..cf737e168 100644 --- a/pkg/handlers/generic/mutation/extraapiservercertsans/variables_test.go +++ b/pkg/handlers/generic/mutation/extraapiservercertsans/variables_test.go @@ -22,20 +22,20 @@ func TestVariableValidation(t *testing.T) { clusterconfig.NewVariable, capitest.VariableTestDef{ Name: "single valid SAN", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ ExtraAPIServerCertSANs: v1alpha1.ExtraAPIServerCertSANs{"a.b.c.example.com"}, }, }, capitest.VariableTestDef{ Name: "single invalid SAN", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ ExtraAPIServerCertSANs: v1alpha1.ExtraAPIServerCertSANs{"invalid:san"}, }, ExpectError: true, }, capitest.VariableTestDef{ Name: "duplicate valid SANs", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ ExtraAPIServerCertSANs: v1alpha1.ExtraAPIServerCertSANs{ "a.b.c.example.com", "a.b.c.example.com", diff --git a/pkg/handlers/generic/mutation/httpproxy/variables_test.go b/pkg/handlers/generic/mutation/httpproxy/variables_test.go index ebeec8a9b..ec597ee46 100644 --- a/pkg/handlers/generic/mutation/httpproxy/variables_test.go +++ b/pkg/handlers/generic/mutation/httpproxy/variables_test.go @@ -23,7 +23,7 @@ func TestVariableValidation(t *testing.T) { // HTTPProxy capitest.VariableTestDef{ Name: "valid proxy config", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ Proxy: &v1alpha1.HTTPProxy{ HTTP: "http://a.b.c.example.com", HTTPS: "https://a.b.c.example.com", diff --git a/pkg/handlers/generic/mutation/imageregistries/credentials/variables_test.go b/pkg/handlers/generic/mutation/imageregistries/credentials/variables_test.go index 89e0b7b57..676062466 100644 --- a/pkg/handlers/generic/mutation/imageregistries/credentials/variables_test.go +++ b/pkg/handlers/generic/mutation/imageregistries/credentials/variables_test.go @@ -23,7 +23,7 @@ func TestVariableValidation(t *testing.T) { clusterconfig.NewVariable, capitest.VariableTestDef{ Name: "without a credentials secret", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ ImageRegistries: []v1alpha1.ImageRegistry{ { URL: "http://a.b.c.example.com", @@ -33,7 +33,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "with a credentials secret", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ ImageRegistries: []v1alpha1.ImageRegistry{ { URL: "https://a.b.c.example.com/a/b/c", @@ -48,7 +48,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "support for multiple image registries", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ ImageRegistries: []v1alpha1.ImageRegistry{ { URL: "http://first-image-registry.example.com", @@ -61,7 +61,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "invalid registry URL", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ ImageRegistries: []v1alpha1.ImageRegistry{ { URL: "unsupportedformat://a.b.c.example.com", @@ -72,7 +72,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "registry URL without format", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ ImageRegistries: []v1alpha1.ImageRegistry{ { URL: "a.b.c.example.com/a/b/c", diff --git a/pkg/handlers/generic/mutation/kubernetesimagerepository/variables_test.go b/pkg/handlers/generic/mutation/kubernetesimagerepository/variables_test.go index 80fc94768..970617b2a 100644 --- a/pkg/handlers/generic/mutation/kubernetesimagerepository/variables_test.go +++ b/pkg/handlers/generic/mutation/kubernetesimagerepository/variables_test.go @@ -23,7 +23,7 @@ func TestVariableValidation(t *testing.T) { // KubernetesImageRepository capitest.VariableTestDef{ Name: "set", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ KubernetesImageRepository: ptr.To( v1alpha1.KubernetesImageRepository("my-registry.io/my-org/my-repo"), ), diff --git a/pkg/handlers/generic/mutation/mirrors/variables_test.go b/pkg/handlers/generic/mutation/mirrors/variables_test.go index 0e735a544..846ad3fa1 100644 --- a/pkg/handlers/generic/mutation/mirrors/variables_test.go +++ b/pkg/handlers/generic/mutation/mirrors/variables_test.go @@ -23,7 +23,7 @@ func TestVariableValidation(t *testing.T) { clusterconfig.NewVariable, capitest.VariableTestDef{ Name: "without a credentials secret", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ GlobalImageRegistryMirror: &v1alpha1.GlobalImageRegistryMirror{ URL: "http://a.b.c.example.com", }, @@ -31,7 +31,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "with a credentials CA secret", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ GlobalImageRegistryMirror: &v1alpha1.GlobalImageRegistryMirror{ URL: "http://a.b.c.example.com", Credentials: &v1alpha1.RegistryCredentials{ @@ -44,7 +44,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "invalid mirror registry URL", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ GlobalImageRegistryMirror: &v1alpha1.GlobalImageRegistryMirror{ URL: "unsupportedformat://a.b.c.example.com", }, @@ -53,7 +53,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "mirror URL without format", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ GlobalImageRegistryMirror: &v1alpha1.GlobalImageRegistryMirror{ URL: "a.b.c.example.com/a/b/c", }, diff --git a/pkg/handlers/generic/mutation/users/variables_test.go b/pkg/handlers/generic/mutation/users/variables_test.go index c7f4ba5bc..a89d527a7 100644 --- a/pkg/handlers/generic/mutation/users/variables_test.go +++ b/pkg/handlers/generic/mutation/users/variables_test.go @@ -22,7 +22,7 @@ func TestVariableValidation(t *testing.T) { clusterconfig.NewVariable, capitest.VariableTestDef{ Name: "valid users", - Vals: v1alpha1.GenericClusterConfig{ + Vals: v1alpha1.GenericClusterConfigSpec{ Users: []v1alpha1.User{ { Name: "complete", diff --git a/pkg/handlers/generic/workerconfig/variables.go b/pkg/handlers/generic/workerconfig/variables.go index 0638d48fd..be2a68d21 100644 --- a/pkg/handlers/generic/workerconfig/variables.go +++ b/pkg/handlers/generic/workerconfig/variables.go @@ -3,49 +3,7 @@ package workerconfig -import ( - "context" - - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" - - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" - commonhandlers "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers" - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation" -) - -var ( - _ commonhandlers.Named = &workerConfigsVariableHandler{} - _ mutation.DiscoverVariables = &workerConfigsVariableHandler{} -) - const ( // MetaVariableName is the meta worker config patch variable name. MetaVariableName = "workerConfig" - - // HandlerNameVariable is the name of the variable handler. - HandlerNameVariable = "WorkerConfigVars" ) - -func NewVariable() *workerConfigsVariableHandler { - return &workerConfigsVariableHandler{} -} - -type workerConfigsVariableHandler struct{} - -func (h *workerConfigsVariableHandler) Name() string { - return HandlerNameVariable -} - -func (h *workerConfigsVariableHandler) DiscoverVariables( - ctx context.Context, - _ *runtimehooksv1.DiscoverVariablesRequest, - resp *runtimehooksv1.DiscoverVariablesResponse, -) { - resp.Variables = append(resp.Variables, clusterv1.ClusterClassVariable{ - Name: MetaVariableName, - Required: false, - Schema: v1alpha1.GenericNodeConfig{}.VariableSchema(), - }) - resp.SetStatus(runtimehooksv1.ResponseStatusSuccess) -} diff --git a/pkg/handlers/generic/workerconfig/variables_test.go b/pkg/handlers/generic/workerconfig/variables_test.go deleted file mode 100644 index 8cfc42cf6..000000000 --- a/pkg/handlers/generic/workerconfig/variables_test.go +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2023 D2iQ, Inc. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package workerconfig - -import ( - "testing" - - "k8s.io/utils/ptr" - - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest" -) - -func TestVariableValidation(t *testing.T) { - capitest.ValidateDiscoverVariables( - t, - MetaVariableName, - ptr.To(v1alpha1.GenericNodeConfig{}.VariableSchema()), - false, - NewVariable, - ) -} diff --git a/pkg/handlers/nutanix/clusterconfig/variables.go b/pkg/handlers/nutanix/clusterconfig/variables.go index a15818846..6a12b8734 100644 --- a/pkg/handlers/nutanix/clusterconfig/variables.go +++ b/pkg/handlers/nutanix/clusterconfig/variables.go @@ -46,7 +46,7 @@ func (h *nutanixClusterConfigVariableHandler) DiscoverVariables( resp.Variables = append(resp.Variables, clusterv1.ClusterClassVariable{ Name: clusterconfig.MetaVariableName, Required: true, - Schema: v1alpha1.ClusterConfigSpec{Nutanix: &v1alpha1.NutanixSpec{}}.VariableSchema(), + Schema: v1alpha1.NutanixClusterConfig{}.VariableSchema(), }) resp.SetStatus(runtimehooksv1.ResponseStatusSuccess) } diff --git a/pkg/handlers/nutanix/mutation/controlplaneendpoint/variables_test.go b/pkg/handlers/nutanix/mutation/controlplaneendpoint/variables_test.go index 172ded87a..f73d11a76 100644 --- a/pkg/handlers/nutanix/mutation/controlplaneendpoint/variables_test.go +++ b/pkg/handlers/nutanix/mutation/controlplaneendpoint/variables_test.go @@ -26,12 +26,12 @@ func TestVariableValidation(t *testing.T) { capitest.ValidateDiscoverVariables( t, clusterconfig.MetaVariableName, - ptr.To(v1alpha1.ClusterConfigSpec{Nutanix: &v1alpha1.NutanixSpec{}}.VariableSchema()), + ptr.To(v1alpha1.NutanixClusterConfig{}.VariableSchema()), true, nutanixclusterconfig.NewVariable, capitest.VariableTestDef{ Name: "valid host and port", - Vals: v1alpha1.ClusterConfigSpec{ + Vals: v1alpha1.NutanixClusterConfigSpec{ Nutanix: &v1alpha1.NutanixSpec{ ControlPlaneEndpoint: clusterv1.APIEndpoint{ Host: "10.20.100.10", @@ -49,7 +49,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "empty host", - Vals: v1alpha1.ClusterConfigSpec{ + Vals: v1alpha1.NutanixClusterConfigSpec{ Nutanix: &v1alpha1.NutanixSpec{ ControlPlaneEndpoint: clusterv1.APIEndpoint{ Host: "", @@ -68,7 +68,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "port set to 0", - Vals: v1alpha1.ClusterConfigSpec{ + Vals: v1alpha1.NutanixClusterConfigSpec{ Nutanix: &v1alpha1.NutanixSpec{ ControlPlaneEndpoint: clusterv1.APIEndpoint{ Host: "10.20.100.10", diff --git a/pkg/handlers/nutanix/mutation/machinedetails/variables_test.go b/pkg/handlers/nutanix/mutation/machinedetails/variables_test.go index e11a9eb22..397c6659d 100644 --- a/pkg/handlers/nutanix/mutation/machinedetails/variables_test.go +++ b/pkg/handlers/nutanix/mutation/machinedetails/variables_test.go @@ -60,7 +60,7 @@ func TestVariableValidation(t *testing.T) { capitest.ValidateDiscoverVariables( t, clusterconfig.MetaVariableName, - ptr.To(v1alpha1.ClusterConfigSpec{Nutanix: &v1alpha1.NutanixSpec{}}.VariableSchema()), + ptr.To(v1alpha1.NutanixClusterConfig{}.VariableSchema()), true, nutanixclusterconfig.NewVariable, capitest.VariableTestDef{ @@ -98,9 +98,9 @@ func TestVariableValidation(t *testing.T) { ) } -func minimumClusterConfigSpec() v1alpha1.ClusterConfigSpec { - return v1alpha1.ClusterConfigSpec{ - ControlPlane: &v1alpha1.NodeConfigSpec{ +func minimumClusterConfigSpec() v1alpha1.NutanixClusterConfigSpec { + return v1alpha1.NutanixClusterConfigSpec{ + ControlPlane: &v1alpha1.NutanixNodeConfigSpec{ Nutanix: &v1alpha1.NutanixNodeSpec{ MachineDetails: v1alpha1.NutanixMachineDetails{ BootType: v1alpha1.NutanixBootType(capxv1.NutanixBootTypeLegacy), diff --git a/pkg/handlers/nutanix/mutation/prismcentralendpoint/variables_test.go b/pkg/handlers/nutanix/mutation/prismcentralendpoint/variables_test.go index bf10166f6..c7d50c79c 100644 --- a/pkg/handlers/nutanix/mutation/prismcentralendpoint/variables_test.go +++ b/pkg/handlers/nutanix/mutation/prismcentralendpoint/variables_test.go @@ -21,12 +21,12 @@ func TestVariableValidation(t *testing.T) { capitest.ValidateDiscoverVariables( t, clusterconfig.MetaVariableName, - ptr.To(v1alpha1.ClusterConfigSpec{Nutanix: &v1alpha1.NutanixSpec{}}.VariableSchema()), + ptr.To(v1alpha1.NutanixClusterConfig{}.VariableSchema()), true, nutanixclusterconfig.NewVariable, capitest.VariableTestDef{ Name: "valid PC URL", - Vals: v1alpha1.ClusterConfigSpec{ + Vals: v1alpha1.NutanixClusterConfigSpec{ Nutanix: &v1alpha1.NutanixSpec{ PrismCentralEndpoint: v1alpha1.NutanixPrismCentralEndpointSpec{ URL: fmt.Sprintf( @@ -48,7 +48,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "valid PC URL as an IP", - Vals: v1alpha1.ClusterConfigSpec{ + Vals: v1alpha1.NutanixClusterConfigSpec{ Nutanix: &v1alpha1.NutanixSpec{ PrismCentralEndpoint: v1alpha1.NutanixPrismCentralEndpointSpec{ URL: fmt.Sprintf( @@ -70,7 +70,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "valid PC URL without a port", - Vals: v1alpha1.ClusterConfigSpec{ + Vals: v1alpha1.NutanixClusterConfigSpec{ Nutanix: &v1alpha1.NutanixSpec{ PrismCentralEndpoint: v1alpha1.NutanixPrismCentralEndpointSpec{ URL: "https://prism-central.nutanix.com", @@ -89,7 +89,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "empty PC URL", - Vals: v1alpha1.ClusterConfigSpec{ + Vals: v1alpha1.NutanixClusterConfigSpec{ Nutanix: &v1alpha1.NutanixSpec{ PrismCentralEndpoint: v1alpha1.NutanixPrismCentralEndpointSpec{ Insecure: false, @@ -108,7 +108,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "http is not a valid PC URL", - Vals: v1alpha1.ClusterConfigSpec{ + Vals: v1alpha1.NutanixClusterConfigSpec{ Nutanix: &v1alpha1.NutanixSpec{ PrismCentralEndpoint: v1alpha1.NutanixPrismCentralEndpointSpec{ URL: "http://prism-central.nutanix.com", @@ -128,7 +128,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "not a valid PC URL", - Vals: v1alpha1.ClusterConfigSpec{ + Vals: v1alpha1.NutanixClusterConfigSpec{ Nutanix: &v1alpha1.NutanixSpec{ PrismCentralEndpoint: v1alpha1.NutanixPrismCentralEndpointSpec{ URL: "not-a-valid-url", @@ -148,7 +148,7 @@ func TestVariableValidation(t *testing.T) { }, capitest.VariableTestDef{ Name: "nil PC credentials", - Vals: v1alpha1.ClusterConfigSpec{ + Vals: v1alpha1.NutanixClusterConfigSpec{ Nutanix: &v1alpha1.NutanixSpec{ PrismCentralEndpoint: v1alpha1.NutanixPrismCentralEndpointSpec{ URL: fmt.Sprintf( diff --git a/pkg/handlers/nutanix/workerconfig/variables.go b/pkg/handlers/nutanix/workerconfig/variables.go index 14d56bd6f..bf8101c2e 100644 --- a/pkg/handlers/nutanix/workerconfig/variables.go +++ b/pkg/handlers/nutanix/workerconfig/variables.go @@ -46,7 +46,7 @@ func (h *nutanixWorkerConfigVariableHandler) DiscoverVariables( resp.Variables = append(resp.Variables, clusterv1.ClusterClassVariable{ Name: workerconfig.MetaVariableName, Required: false, - Schema: v1alpha1.NodeConfigSpec{Nutanix: &v1alpha1.NutanixNodeSpec{}}.VariableSchema(), + Schema: v1alpha1.NutanixNodeConfig{}.VariableSchema(), }) resp.SetStatus(runtimehooksv1.ResponseStatusSuccess) } diff --git a/pkg/handlers/nutanix/workerconfig/variables_test.go b/pkg/handlers/nutanix/workerconfig/variables_test.go index 87a6e4105..b300ee2f9 100644 --- a/pkg/handlers/nutanix/workerconfig/variables_test.go +++ b/pkg/handlers/nutanix/workerconfig/variables_test.go @@ -17,7 +17,7 @@ func TestVariableValidation(t *testing.T) { capitest.ValidateDiscoverVariables( t, workerconfig.MetaVariableName, - ptr.To(v1alpha1.NodeConfigSpec{Nutanix: &v1alpha1.NutanixNodeSpec{}}.VariableSchema()), + ptr.To(v1alpha1.NutanixNodeConfig{}.VariableSchema()), false, NewVariable, ) From 420eb1640e10ac352314ccddc62c932c79b116cb Mon Sep 17 00:00:00 2001 From: Jimmi Dyson Date: Thu, 18 Apr 2024 17:20:53 +0100 Subject: [PATCH 2/6] fixup! refactor: Add more kubebuilder annotations --- api/v1alpha1/addon_types.go | 39 +++++-- api/v1alpha1/aws_clusterconfig_types.go | 10 +- api/v1alpha1/clusterconfig_types.go | 42 ++++---- api/v1alpha1/common_types.go | 15 ++- .../caren.nutanix.com_awsclusterconfigs.yaml | 101 +++++++++++++++--- ...aren.nutanix.com_dockerclusterconfigs.yaml | 90 ++++++++++++++-- .../caren.nutanix.com_dockernodeconfigs.yaml | 2 + ...ren.nutanix.com_genericclusterconfigs.yaml | 87 +++++++++++++-- ...ren.nutanix.com_nutanixclusterconfigs.yaml | 100 ++++++++++++++--- .../caren.nutanix.com_nutanixnodeconfigs.yaml | 3 + api/v1alpha1/docker_node_types.go | 22 +--- api/v1alpha1/nodeconfig_types.go | 4 +- api/v1alpha1/nutanix_clusterconfig_types.go | 14 +-- api/v1alpha1/nutanix_node_types.go | 2 + api/v1alpha1/zz_generated.deepcopy.go | 77 ++----------- .../customimage/inject_control_plane.go | 9 +- .../mutation/customimage/inject_worker.go | 9 +- .../mutation/customimage/variables_test.go | 4 +- .../generic/clusterconfig/variables_test.go | 2 +- .../mutation/extraapiservercertsans/inject.go | 2 +- .../extraapiservercertsans/inject_test.go | 6 +- .../extraapiservercertsans/variables_test.go | 6 +- .../imageregistries/credentials/inject.go | 2 +- .../credentials/inject_test.go | 52 ++++----- .../kubernetesimagerepository/inject.go | 5 +- .../kubernetesimagerepository/inject_test.go | 3 +- .../variables_test.go | 2 +- pkg/handlers/generic/mutation/users/inject.go | 2 +- .../controlplaneendpoint/inject_test.go | 4 +- .../controlplaneendpoint/variables_test.go | 13 ++- .../prismcentralendpoint/inject_test.go | 6 +- .../prismcentralendpoint/variables_test.go | 27 +++-- 32 files changed, 494 insertions(+), 268 deletions(-) diff --git a/api/v1alpha1/addon_types.go b/api/v1alpha1/addon_types.go index 5987ebd89..9395ff58e 100644 --- a/api/v1alpha1/addon_types.go +++ b/api/v1alpha1/addon_types.go @@ -40,26 +40,34 @@ type AddonStrategy string // CNI required for providing CNI configuration. type CNI struct { - // +optional - Provider string `json:"provider,omitempty"` - // +optional - Strategy AddonStrategy `json:"strategy,omitempty"` + // CNI provider to deploy. + // +kubebuilder:validation:Enum=Calico;Cilium + Provider string `json:"provider"` + // Addon strategy used to deploy the CNI provider to the workload cluster. + // +kubebuilder:validation:Enum=ClusterResourceSet;HelmAddon + Strategy AddonStrategy `json:"strategy"` } // NFD tells us to enable or disable the node feature discovery addon. type NFD struct { - // +optional - Strategy AddonStrategy `json:"strategy,omitempty"` + // Addon strategy used to deploy Node Feature Discovery (NFD) to the workload cluster. + // +kubebuilder:validation:Enum=ClusterResourceSet;HelmAddon + Strategy AddonStrategy `json:"strategy"` } // ClusterAutoscaler tells us to enable or disable the cluster-autoscaler addon. type ClusterAutoscaler struct { - // +optional - Strategy AddonStrategy `json:"strategy,omitempty"` + // Addon strategy used to deploy cluster-autoscaler to the management cluster + // targeting the workload cluster. + // +kubebuilder:validation:Enum=ClusterResourceSet;HelmAddon + Strategy AddonStrategy `json:"strategy"` } type DefaultStorage struct { - ProviderName string `json:"providerName"` + // Name of the CSI Provider for the default storage class. + // +kubebuilder:validation:Enum=aws-ebs;nutanix + ProviderName string `json:"providerName"` + // Name of storage class config in any of the provider objects. StorageClassConfigName string `json:"storageClassConfigName"` } @@ -71,29 +79,42 @@ type CSI struct { } type CSIProvider struct { + // Name of the CSI Provider. + // +kubebuilder:validation:Enum=aws-ebs;nutanix Name string `json:"name"` // +optional StorageClassConfig []StorageClassConfig `json:"storageClassConfig,omitempty"` + // Addon strategy used to deploy the CSI provider to the workload cluster. + // +kubebuilder:validation:Enum=ClusterResourceSet;HelmAddon Strategy AddonStrategy `json:"strategy"` + // The reference to any secret used by the CSI Provider. // +optional Credentials *corev1.LocalObjectReference `json:"credentials,omitempty"` } type StorageClassConfig struct { + // Name of storage class config. Name string `json:"name"` + // Parameters passed into the storage class object. // +optional Parameters map[string]string `json:"parameters,omitempty"` + // +kubebuilder:validation:Enum=Delete;Retain;Recycle + // +kubebuilder:default=Delete // +optional ReclaimPolicy corev1.PersistentVolumeReclaimPolicy `json:"reclaimPolicy,omitempty"` + // +kubebuilder:validation:Enum=Immediate;WaitForFirstConsumer + // +kubebuilder:default=WaitForFirstConsumer // +optional VolumeBindingMode storagev1.VolumeBindingMode `json:"volumeBindingMode,omitempty"` + // If the storage class should allow volume expanding + // +kubebuilder:default=false // +optional AllowExpansion bool `json:"allowExpansion,omitempty"` } diff --git a/api/v1alpha1/aws_clusterconfig_types.go b/api/v1alpha1/aws_clusterconfig_types.go index 397242222..049469868 100644 --- a/api/v1alpha1/aws_clusterconfig_types.go +++ b/api/v1alpha1/aws_clusterconfig_types.go @@ -11,6 +11,7 @@ type AWSSpec struct { // AWS region to create cluster in. // +optional Region *Region `json:"region,omitempty"` + // AWS network configuration. // +optional Network *AWSNetwork `json:"network,omitempty"` // +optional @@ -23,26 +24,27 @@ type AWSNetwork struct { // +optional VPC *VPC `json:"vpc,omitempty"` + // AWS Subnet configuration. // +optional Subnets Subnets `json:"subnets,omitempty"` } type VPC struct { - // ID is the vpc-id of the VPC this provider should use to create resources. - ID string `json:"id,omitempty"` + // Existing VPC ID to use for the cluster. + ID string `json:"id"` } type Subnets []SubnetSpec // SubnetSpec configures an AWS Subnet. type SubnetSpec struct { - // ID defines a unique identifier to reference this resource. + // Existing Subnet ID to use for the cluster. ID string `json:"id"` } // AWSLoadBalancerSpec configures an AWS control-plane LoadBalancer. type AWSLoadBalancerSpec struct { - // Scheme sets the scheme of the load balancer (defaults to internet-facing) + // Scheme sets the scheme of the load balancer. // +kubebuilder:default=internet-facing // +kubebuilder:validation:Enum=internet-facing;internal // +optional diff --git a/api/v1alpha1/clusterconfig_types.go b/api/v1alpha1/clusterconfig_types.go index 5f6ff4b14..573262ff4 100644 --- a/api/v1alpha1/clusterconfig_types.go +++ b/api/v1alpha1/clusterconfig_types.go @@ -82,6 +82,7 @@ func (s AWSClusterConfig) VariableSchema() clusterv1.VariableSchema { //nolint:g // AWSClusterConfigSpec defines the desired state of ClusterConfig. type AWSClusterConfigSpec struct { + // AWS cluster configuration. // +optional AWS *AWSSpec `json:"aws,omitempty"` @@ -160,8 +161,10 @@ func (s GenericClusterConfig) VariableSchema() clusterv1.VariableSchema { //noli // GenericClusterConfigSpec defines the desired state of GenericClusterConfig. type GenericClusterConfigSpec struct { + // Sets the Kubernetes image repository used for the KubeadmControlPlane. + // +kubebuilder:validation:Pattern=`^((?:[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*|\[(?:[a-fA-F0-9:]+)\])(:[0-9]+)?/)?[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*(/[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*)*$` // +optional - KubernetesImageRepository *KubernetesImageRepository `json:"kubernetesImageRepository,omitempty"` + KubernetesImageRepository *string `json:"kubernetesImageRepository,omitempty"` // +optional Etcd *Etcd `json:"etcd,omitempty"` @@ -169,11 +172,16 @@ type GenericClusterConfigSpec struct { // +optional Proxy *HTTPProxy `json:"proxy,omitempty"` + // Subject Alternative Names for the API Server signing cert. + // For Docker are injected automatically. + // For Nutanix are injected automatically. + // +kubebuilder:validation:UniqueItems=true + // +kubebuilder:validation:items:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$` // +optional - ExtraAPIServerCertSANs ExtraAPIServerCertSANs `json:"extraAPIServerCertSANs,omitempty"` + ExtraAPIServerCertSANs []string `json:"extraAPIServerCertSANs,omitempty"` // +optional - ImageRegistries ImageRegistries `json:"imageRegistries,omitempty"` + ImageRegistries []ImageRegistry `json:"imageRegistries,omitempty"` // +optional GlobalImageRegistryMirror *GlobalImageRegistryMirror `json:"globalImageRegistryMirror,omitempty"` @@ -182,22 +190,17 @@ type GenericClusterConfigSpec struct { Addons *Addons `json:"addons,omitempty"` // +optional - Users Users `json:"users,omitempty"` -} - -// KubernetesImageRepository required for overriding Kubernetes image repository. -type KubernetesImageRepository string - -func (v KubernetesImageRepository) String() string { - return string(v) + Users []User `json:"users,omitempty"` } type Image struct { // Repository is used to override the image repository to pull from. + // +kubebuilder:validation:Pattern=`^((?:[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*|\[(?:[a-fA-F0-9:]+)\])(:[0-9]+)?/)?[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*(/[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*)*$` // +optional Repository string `json:"repository,omitempty"` // Tag is used to override the default image tag. + // +kubebuilder:validation:Pattern=`^[\w][\w.-]{0,127}$` // +optional Tag string `json:"tag,omitempty"` } @@ -210,10 +213,10 @@ type Etcd struct { // HTTPProxy required for providing proxy configuration. type HTTPProxy struct { - // HTTP proxy. + // HTTP proxy value. HTTP string `json:"http,omitempty"` - // HTTPS proxy. + // HTTPS proxy value. HTTPS string `json:"https,omitempty"` // AdditionalNo Proxy list that will be added to the automatically calculated @@ -223,9 +226,6 @@ type HTTPProxy struct { AdditionalNo []string `json:"additionalNo"` } -// ExtraAPIServerCertSANs required for providing API server cert SANs. -type ExtraAPIServerCertSANs []string - type RegistryCredentials struct { // A reference to the Secret containing the registry credentials and optional CA certificate // using the keys `username`, `password` and `ca.crt`. @@ -236,7 +236,9 @@ type RegistryCredentials struct { // GlobalImageRegistryMirror sets default mirror configuration for all the image registries. type GlobalImageRegistryMirror struct { - // Registry URL. + // Registry mirror URL. + // +kubebuilder:validation:Format=`uri` + // +kubebuilder:validation:Pattern=`^https?://` URL string `json:"url"` // Credentials and CA certificate for the image registry mirror @@ -246,6 +248,8 @@ type GlobalImageRegistryMirror struct { type ImageRegistry struct { // Registry URL. + // +kubebuilder:validation:Format=`uri` + // +kubebuilder:validation:Pattern=`^https?://` URL string `json:"url"` // Credentials and CA certificate for the image registry @@ -253,10 +257,6 @@ type ImageRegistry struct { Credentials *RegistryCredentials `json:"credentials,omitempty"` } -type ImageRegistries []ImageRegistry - -type Users []User - // User defines the input for a generated user in cloud-init. type User struct { // Name specifies the user name. diff --git a/api/v1alpha1/common_types.go b/api/v1alpha1/common_types.go index a9132ca50..11d1321f8 100644 --- a/api/v1alpha1/common_types.go +++ b/api/v1alpha1/common_types.go @@ -3,10 +3,6 @@ package v1alpha1 -import ( - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" -) - const ( APIServerPort = 6443 ) @@ -32,4 +28,13 @@ type ObjectMeta struct { Annotations map[string]string `json:"annotations,omitempty"` } -type ControlPlaneEndpointSpec clusterv1.APIEndpoint +type ControlPlaneEndpointSpec struct { + // The hostname on which the API server is serving. + // +kubebuilder:validation:MinLength=1 + Host string `json:"host"` + + // The port on which the API server is serving. + // +kubebuilder:validation:Minimum=1 + // +kubebuilder:validation:Maximum=65535 + Port int32 `json:"port"` +} diff --git a/api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml index 87ec0f782..2372df367 100644 --- a/api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml +++ b/api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml @@ -65,23 +65,50 @@ spec: cluster-autoscaler addon. properties: strategy: + description: |- + Addon strategy used to deploy cluster-autoscaler to the management cluster + targeting the workload cluster. + enum: + - ClusterResourceSet + - HelmAddon type: string + required: + - strategy type: object cni: description: CNI required for providing CNI configuration. properties: provider: + description: CNI provider to deploy. + enum: + - Calico + - Cilium type: string strategy: + description: Addon strategy used to deploy the CNI provider + to the workload cluster. + enum: + - ClusterResourceSet + - HelmAddon type: string + required: + - provider + - strategy type: object csi: properties: defaultStorage: properties: providerName: + description: Name of the CSI Provider for the default + storage class. + enum: + - aws-ebs + - nutanix type: string storageClassConfigName: + description: Name of storage class config in any of the + provider objects. type: string required: - providerName @@ -91,9 +118,8 @@ spec: items: properties: credentials: - description: |- - LocalObjectReference contains enough information to let you locate the - referenced object inside the same namespace. + description: The reference to any secret used by the + CSI Provider. properties: name: description: |- @@ -104,32 +130,56 @@ spec: type: object x-kubernetes-map-type: atomic name: + description: Name of the CSI Provider. + enum: + - aws-ebs + - nutanix type: string storageClassConfig: items: properties: allowExpansion: + default: false + description: If the storage class should allow + volume expanding type: boolean name: + description: Name of storage class config. type: string parameters: additionalProperties: type: string + description: Parameters passed into the storage + class object. type: object reclaimPolicy: + default: Delete description: PersistentVolumeReclaimPolicy describes a policy for end-of-life maintenance of persistent volumes. + enum: + - Delete + - Retain + - Recycle type: string volumeBindingMode: + default: WaitForFirstConsumer description: VolumeBindingMode indicates how PersistentVolumeClaims should be bound. + enum: + - Immediate + - WaitForFirstConsumer type: string required: - name type: object type: array strategy: + description: Addon strategy used to deploy the CSI provider + to the workload cluster. + enum: + - ClusterResourceSet + - HelmAddon type: string required: - name @@ -142,10 +192,18 @@ spec: discovery addon. properties: strategy: + description: Addon strategy used to deploy Node Feature Discovery + (NFD) to the workload cluster. + enum: + - ClusterResourceSet + - HelmAddon type: string + required: + - strategy type: object type: object aws: + description: AWS cluster configuration. properties: controlPlaneLoadBalancer: description: AWSLoadBalancerSpec configures an AWS control-plane @@ -153,22 +211,22 @@ spec: properties: scheme: default: internet-facing - description: Scheme sets the scheme of the load balancer (defaults - to internet-facing) + description: Scheme sets the scheme of the load balancer. enum: - internet-facing - internal type: string type: object network: + description: AWS network configuration. properties: subnets: + description: AWS Subnet configuration. items: description: SubnetSpec configures an AWS Subnet. properties: id: - description: ID defines a unique identifier to reference - this resource. + description: Existing Subnet ID to use for the cluster. type: string required: - id @@ -177,9 +235,10 @@ spec: vpc: properties: id: - description: ID is the vpc-id of the VPC this provider - should use to create resources. + description: Existing VPC ID to use for the cluster. type: string + required: + - id type: object type: object region: @@ -240,18 +299,24 @@ spec: repository: description: Repository is used to override the image repository to pull from. + pattern: ^((?:[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*|\[(?:[a-fA-F0-9:]+)\])(:[0-9]+)?/)?[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*(/[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*)*$ type: string tag: description: Tag is used to override the default image tag. + pattern: ^[\w][\w.-]{0,127}$ type: string type: object type: object extraAPIServerCertSANs: - description: ExtraAPIServerCertSANs required for providing API server - cert SANs. + description: |- + Subject Alternative Names for the API Server signing cert. + For Docker are injected automatically. + For Nutanix are injected automatically. items: + pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ type: string type: array + uniqueItems: true globalImageRegistryMirror: description: GlobalImageRegistryMirror sets default mirror configuration for all the image registries. @@ -276,7 +341,9 @@ spec: x-kubernetes-map-type: atomic type: object url: - description: Registry URL. + description: Registry mirror URL. + format: uri + pattern: ^https?:// type: string required: - url @@ -304,14 +371,16 @@ spec: type: object url: description: Registry URL. + format: uri + pattern: ^https?:// type: string required: - url type: object type: array kubernetesImageRepository: - description: KubernetesImageRepository required for overriding Kubernetes - image repository. + description: Sets the Kubernetes image repository used for the KubeadmControlPlane. + pattern: ^((?:[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*|\[(?:[a-fA-F0-9:]+)\])(:[0-9]+)?/)?[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*(/[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*)*$ type: string proxy: description: HTTPProxy required for providing proxy configuration. @@ -326,10 +395,10 @@ spec: type: string type: array http: - description: HTTP proxy. + description: HTTP proxy value. type: string https: - description: HTTPS proxy. + description: HTTPS proxy value. type: string required: - additionalNo diff --git a/api/v1alpha1/crds/caren.nutanix.com_dockerclusterconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_dockerclusterconfigs.yaml index 31e67a3b6..c6aca6fb7 100644 --- a/api/v1alpha1/crds/caren.nutanix.com_dockerclusterconfigs.yaml +++ b/api/v1alpha1/crds/caren.nutanix.com_dockerclusterconfigs.yaml @@ -66,23 +66,50 @@ spec: cluster-autoscaler addon. properties: strategy: + description: |- + Addon strategy used to deploy cluster-autoscaler to the management cluster + targeting the workload cluster. + enum: + - ClusterResourceSet + - HelmAddon type: string + required: + - strategy type: object cni: description: CNI required for providing CNI configuration. properties: provider: + description: CNI provider to deploy. + enum: + - Calico + - Cilium type: string strategy: + description: Addon strategy used to deploy the CNI provider + to the workload cluster. + enum: + - ClusterResourceSet + - HelmAddon type: string + required: + - provider + - strategy type: object csi: properties: defaultStorage: properties: providerName: + description: Name of the CSI Provider for the default + storage class. + enum: + - aws-ebs + - nutanix type: string storageClassConfigName: + description: Name of storage class config in any of the + provider objects. type: string required: - providerName @@ -92,9 +119,8 @@ spec: items: properties: credentials: - description: |- - LocalObjectReference contains enough information to let you locate the - referenced object inside the same namespace. + description: The reference to any secret used by the + CSI Provider. properties: name: description: |- @@ -105,32 +131,56 @@ spec: type: object x-kubernetes-map-type: atomic name: + description: Name of the CSI Provider. + enum: + - aws-ebs + - nutanix type: string storageClassConfig: items: properties: allowExpansion: + default: false + description: If the storage class should allow + volume expanding type: boolean name: + description: Name of storage class config. type: string parameters: additionalProperties: type: string + description: Parameters passed into the storage + class object. type: object reclaimPolicy: + default: Delete description: PersistentVolumeReclaimPolicy describes a policy for end-of-life maintenance of persistent volumes. + enum: + - Delete + - Retain + - Recycle type: string volumeBindingMode: + default: WaitForFirstConsumer description: VolumeBindingMode indicates how PersistentVolumeClaims should be bound. + enum: + - Immediate + - WaitForFirstConsumer type: string required: - name type: object type: array strategy: + description: Addon strategy used to deploy the CSI provider + to the workload cluster. + enum: + - ClusterResourceSet + - HelmAddon type: string required: - name @@ -143,7 +193,14 @@ spec: discovery addon. properties: strategy: + description: Addon strategy used to deploy Node Feature Discovery + (NFD) to the workload cluster. + enum: + - ClusterResourceSet + - HelmAddon type: string + required: + - strategy type: object type: object controlPlane: @@ -152,6 +209,9 @@ spec: docker: properties: customImage: + description: Custom OCI image for control plane and worker + Nodes. + pattern: ^((?:[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*|\[(?:[a-fA-F0-9:]+)\])(:[0-9]+)?/)?[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*(/[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*)*(:[\w][\w.-]{0,127})?(@[A-Za-z][A-Za-z0-9]*(?:[-_+.][A-Za-z][A-Za-z0-9]*)*[:][0-9A-Fa-f]{32,})?$ type: string type: object type: object @@ -165,18 +225,24 @@ spec: repository: description: Repository is used to override the image repository to pull from. + pattern: ^((?:[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*|\[(?:[a-fA-F0-9:]+)\])(:[0-9]+)?/)?[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*(/[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*)*$ type: string tag: description: Tag is used to override the default image tag. + pattern: ^[\w][\w.-]{0,127}$ type: string type: object type: object extraAPIServerCertSANs: - description: ExtraAPIServerCertSANs required for providing API server - cert SANs. + description: |- + Subject Alternative Names for the API Server signing cert. + For Docker are injected automatically. + For Nutanix are injected automatically. items: + pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ type: string type: array + uniqueItems: true globalImageRegistryMirror: description: GlobalImageRegistryMirror sets default mirror configuration for all the image registries. @@ -201,7 +267,9 @@ spec: x-kubernetes-map-type: atomic type: object url: - description: Registry URL. + description: Registry mirror URL. + format: uri + pattern: ^https?:// type: string required: - url @@ -229,14 +297,16 @@ spec: type: object url: description: Registry URL. + format: uri + pattern: ^https?:// type: string required: - url type: object type: array kubernetesImageRepository: - description: KubernetesImageRepository required for overriding Kubernetes - image repository. + description: Sets the Kubernetes image repository used for the KubeadmControlPlane. + pattern: ^((?:[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*|\[(?:[a-fA-F0-9:]+)\])(:[0-9]+)?/)?[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*(/[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*)*$ type: string proxy: description: HTTPProxy required for providing proxy configuration. @@ -251,10 +321,10 @@ spec: type: string type: array http: - description: HTTP proxy. + description: HTTP proxy value. type: string https: - description: HTTPS proxy. + description: HTTPS proxy value. type: string required: - additionalNo diff --git a/api/v1alpha1/crds/caren.nutanix.com_dockernodeconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_dockernodeconfigs.yaml index 8bf792187..c5189c1ee 100644 --- a/api/v1alpha1/crds/caren.nutanix.com_dockernodeconfigs.yaml +++ b/api/v1alpha1/crds/caren.nutanix.com_dockernodeconfigs.yaml @@ -44,6 +44,8 @@ spec: docker: properties: customImage: + description: Custom OCI image for control plane and worker Nodes. + pattern: ^((?:[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*|\[(?:[a-fA-F0-9:]+)\])(:[0-9]+)?/)?[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*(/[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*)*(:[\w][\w.-]{0,127})?(@[A-Za-z][A-Za-z0-9]*(?:[-_+.][A-Za-z][A-Za-z0-9]*)*[:][0-9A-Fa-f]{32,})?$ type: string type: object type: object diff --git a/api/v1alpha1/crds/caren.nutanix.com_genericclusterconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_genericclusterconfigs.yaml index df7f5fecb..0042f5cea 100644 --- a/api/v1alpha1/crds/caren.nutanix.com_genericclusterconfigs.yaml +++ b/api/v1alpha1/crds/caren.nutanix.com_genericclusterconfigs.yaml @@ -65,23 +65,50 @@ spec: cluster-autoscaler addon. properties: strategy: + description: |- + Addon strategy used to deploy cluster-autoscaler to the management cluster + targeting the workload cluster. + enum: + - ClusterResourceSet + - HelmAddon type: string + required: + - strategy type: object cni: description: CNI required for providing CNI configuration. properties: provider: + description: CNI provider to deploy. + enum: + - Calico + - Cilium type: string strategy: + description: Addon strategy used to deploy the CNI provider + to the workload cluster. + enum: + - ClusterResourceSet + - HelmAddon type: string + required: + - provider + - strategy type: object csi: properties: defaultStorage: properties: providerName: + description: Name of the CSI Provider for the default + storage class. + enum: + - aws-ebs + - nutanix type: string storageClassConfigName: + description: Name of storage class config in any of the + provider objects. type: string required: - providerName @@ -91,9 +118,8 @@ spec: items: properties: credentials: - description: |- - LocalObjectReference contains enough information to let you locate the - referenced object inside the same namespace. + description: The reference to any secret used by the + CSI Provider. properties: name: description: |- @@ -104,32 +130,56 @@ spec: type: object x-kubernetes-map-type: atomic name: + description: Name of the CSI Provider. + enum: + - aws-ebs + - nutanix type: string storageClassConfig: items: properties: allowExpansion: + default: false + description: If the storage class should allow + volume expanding type: boolean name: + description: Name of storage class config. type: string parameters: additionalProperties: type: string + description: Parameters passed into the storage + class object. type: object reclaimPolicy: + default: Delete description: PersistentVolumeReclaimPolicy describes a policy for end-of-life maintenance of persistent volumes. + enum: + - Delete + - Retain + - Recycle type: string volumeBindingMode: + default: WaitForFirstConsumer description: VolumeBindingMode indicates how PersistentVolumeClaims should be bound. + enum: + - Immediate + - WaitForFirstConsumer type: string required: - name type: object type: array strategy: + description: Addon strategy used to deploy the CSI provider + to the workload cluster. + enum: + - ClusterResourceSet + - HelmAddon type: string required: - name @@ -142,7 +192,14 @@ spec: discovery addon. properties: strategy: + description: Addon strategy used to deploy Node Feature Discovery + (NFD) to the workload cluster. + enum: + - ClusterResourceSet + - HelmAddon type: string + required: + - strategy type: object type: object etcd: @@ -153,18 +210,24 @@ spec: repository: description: Repository is used to override the image repository to pull from. + pattern: ^((?:[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*|\[(?:[a-fA-F0-9:]+)\])(:[0-9]+)?/)?[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*(/[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*)*$ type: string tag: description: Tag is used to override the default image tag. + pattern: ^[\w][\w.-]{0,127}$ type: string type: object type: object extraAPIServerCertSANs: - description: ExtraAPIServerCertSANs required for providing API server - cert SANs. + description: |- + Subject Alternative Names for the API Server signing cert. + For Docker are injected automatically. + For Nutanix are injected automatically. items: + pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ type: string type: array + uniqueItems: true globalImageRegistryMirror: description: GlobalImageRegistryMirror sets default mirror configuration for all the image registries. @@ -189,7 +252,9 @@ spec: x-kubernetes-map-type: atomic type: object url: - description: Registry URL. + description: Registry mirror URL. + format: uri + pattern: ^https?:// type: string required: - url @@ -217,14 +282,16 @@ spec: type: object url: description: Registry URL. + format: uri + pattern: ^https?:// type: string required: - url type: object type: array kubernetesImageRepository: - description: KubernetesImageRepository required for overriding Kubernetes - image repository. + description: Sets the Kubernetes image repository used for the KubeadmControlPlane. + pattern: ^((?:[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*|\[(?:[a-fA-F0-9:]+)\])(:[0-9]+)?/)?[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*(/[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*)*$ type: string proxy: description: HTTPProxy required for providing proxy configuration. @@ -239,10 +306,10 @@ spec: type: string type: array http: - description: HTTP proxy. + description: HTTP proxy value. type: string https: - description: HTTPS proxy. + description: HTTPS proxy value. type: string required: - additionalNo diff --git a/api/v1alpha1/crds/caren.nutanix.com_nutanixclusterconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_nutanixclusterconfigs.yaml index 428f0e7d5..fa546edff 100644 --- a/api/v1alpha1/crds/caren.nutanix.com_nutanixclusterconfigs.yaml +++ b/api/v1alpha1/crds/caren.nutanix.com_nutanixclusterconfigs.yaml @@ -66,23 +66,50 @@ spec: cluster-autoscaler addon. properties: strategy: + description: |- + Addon strategy used to deploy cluster-autoscaler to the management cluster + targeting the workload cluster. + enum: + - ClusterResourceSet + - HelmAddon type: string + required: + - strategy type: object cni: description: CNI required for providing CNI configuration. properties: provider: + description: CNI provider to deploy. + enum: + - Calico + - Cilium type: string strategy: + description: Addon strategy used to deploy the CNI provider + to the workload cluster. + enum: + - ClusterResourceSet + - HelmAddon type: string + required: + - provider + - strategy type: object csi: properties: defaultStorage: properties: providerName: + description: Name of the CSI Provider for the default + storage class. + enum: + - aws-ebs + - nutanix type: string storageClassConfigName: + description: Name of storage class config in any of the + provider objects. type: string required: - providerName @@ -92,9 +119,8 @@ spec: items: properties: credentials: - description: |- - LocalObjectReference contains enough information to let you locate the - referenced object inside the same namespace. + description: The reference to any secret used by the + CSI Provider. properties: name: description: |- @@ -105,32 +131,56 @@ spec: type: object x-kubernetes-map-type: atomic name: + description: Name of the CSI Provider. + enum: + - aws-ebs + - nutanix type: string storageClassConfig: items: properties: allowExpansion: + default: false + description: If the storage class should allow + volume expanding type: boolean name: + description: Name of storage class config. type: string parameters: additionalProperties: type: string + description: Parameters passed into the storage + class object. type: object reclaimPolicy: + default: Delete description: PersistentVolumeReclaimPolicy describes a policy for end-of-life maintenance of persistent volumes. + enum: + - Delete + - Retain + - Recycle type: string volumeBindingMode: + default: WaitForFirstConsumer description: VolumeBindingMode indicates how PersistentVolumeClaims should be bound. + enum: + - Immediate + - WaitForFirstConsumer type: string required: - name type: object type: array strategy: + description: Addon strategy used to deploy the CSI provider + to the workload cluster. + enum: + - ClusterResourceSet + - HelmAddon type: string required: - name @@ -143,7 +193,14 @@ spec: discovery addon. properties: strategy: + description: Addon strategy used to deploy Node Feature Discovery + (NFD) to the workload cluster. + enum: + - ClusterResourceSet + - HelmAddon type: string + required: + - strategy type: object type: object controlPlane: @@ -171,6 +228,9 @@ spec: bootType: description: Defines the boot type of the virtual machine. Only supports UEFI and Legacy + enum: + - legacy + - uefi type: string cluster: description: |- @@ -313,18 +373,24 @@ spec: repository: description: Repository is used to override the image repository to pull from. + pattern: ^((?:[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*|\[(?:[a-fA-F0-9:]+)\])(:[0-9]+)?/)?[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*(/[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*)*$ type: string tag: description: Tag is used to override the default image tag. + pattern: ^[\w][\w.-]{0,127}$ type: string type: object type: object extraAPIServerCertSANs: - description: ExtraAPIServerCertSANs required for providing API server - cert SANs. + description: |- + Subject Alternative Names for the API Server signing cert. + For Docker are injected automatically. + For Nutanix are injected automatically. items: + pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ type: string type: array + uniqueItems: true globalImageRegistryMirror: description: GlobalImageRegistryMirror sets default mirror configuration for all the image registries. @@ -349,7 +415,9 @@ spec: x-kubernetes-map-type: atomic type: object url: - description: Registry URL. + description: Registry mirror URL. + format: uri + pattern: ^https?:// type: string required: - url @@ -377,14 +445,16 @@ spec: type: object url: description: Registry URL. + format: uri + pattern: ^https?:// type: string required: - url type: object type: array kubernetesImageRepository: - description: KubernetesImageRepository required for overriding Kubernetes - image repository. + description: Sets the Kubernetes image repository used for the KubeadmControlPlane. + pattern: ^((?:[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*|\[(?:[a-fA-F0-9:]+)\])(:[0-9]+)?/)?[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*(/[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*)*$ type: string nutanix: description: NutanixSpec defines the desired state of NutanixCluster. @@ -396,10 +466,13 @@ spec: properties: host: description: The hostname on which the API server is serving. + minLength: 1 type: string port: description: The port on which the API server is serving. format: int32 + maximum: 65535 + minimum: 1 type: integer required: - host @@ -413,10 +486,11 @@ spec: A base64 PEM encoded x509 cert for the RootCA that was used to create the certificate for a Prism Central that uses certificates that were issued by a non-publicly trusted RootCA. The trust bundle is added to the cert pool used to authenticate the TLS connection to the Prism Central. + format: byte type: string credentials: description: A reference to the Secret for credential information - for the target Prism Central instance + for the target Prism Central instance. properties: name: description: |- @@ -431,7 +505,9 @@ spec: type: boolean url: description: The URL of Nutanix Prism Central, can be DNS - name or an IP address + name or an IP address. + format: uri + pattern: ^https:// type: string required: - credentials @@ -454,10 +530,10 @@ spec: type: string type: array http: - description: HTTP proxy. + description: HTTP proxy value. type: string https: - description: HTTPS proxy. + description: HTTPS proxy value. type: string required: - additionalNo diff --git a/api/v1alpha1/crds/caren.nutanix.com_nutanixnodeconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_nutanixnodeconfigs.yaml index 6ff597a9c..d06c890a8 100644 --- a/api/v1alpha1/crds/caren.nutanix.com_nutanixnodeconfigs.yaml +++ b/api/v1alpha1/crds/caren.nutanix.com_nutanixnodeconfigs.yaml @@ -63,6 +63,9 @@ spec: bootType: description: Defines the boot type of the virtual machine. Only supports UEFI and Legacy + enum: + - legacy + - uefi type: string cluster: description: |- diff --git a/api/v1alpha1/docker_node_types.go b/api/v1alpha1/docker_node_types.go index cad61fd78..da8bf5ad3 100644 --- a/api/v1alpha1/docker_node_types.go +++ b/api/v1alpha1/docker_node_types.go @@ -3,25 +3,9 @@ package v1alpha1 -import ( - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/openapi/patterns" -) - type DockerNodeSpec struct { + // Custom OCI image for control plane and worker Nodes. + // +kubebuilder:validation:Pattern=`^((?:[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*|\[(?:[a-fA-F0-9:]+)\])(:[0-9]+)?/)?[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*(/[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*)*(:[\w][\w.-]{0,127})?(@[A-Za-z][A-Za-z0-9]*(?:[-_+.][A-Za-z][A-Za-z0-9]*)*[:][0-9A-Fa-f]{32,})?$` // +optional - CustomImage *OCIImage `json:"customImage,omitempty"` -} - -type OCIImage string - -func (OCIImage) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "Custom OCI image for control plane and worker Nodes.", - Type: "string", - Pattern: patterns.Anchored(patterns.ImageReference), - }, - } + CustomImage *string `json:"customImage,omitempty"` } diff --git a/api/v1alpha1/nodeconfig_types.go b/api/v1alpha1/nodeconfig_types.go index 9854652cc..eaae20980 100644 --- a/api/v1alpha1/nodeconfig_types.go +++ b/api/v1alpha1/nodeconfig_types.go @@ -27,7 +27,7 @@ var ( ) ) -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // AWSNodeConfig is the Schema for the awsnodeconfigs API. type AWSNodeConfig struct { @@ -50,7 +50,7 @@ type AWSNodeConfigSpec struct { AWS *AWSNodeSpec `json:"aws,omitempty"` } -//+kubebuilder:object:root=true +// +kubebuilder:object:root=true // DockerNodeConfig is the Schema for the dockernodeconfigs API. type DockerNodeConfig struct { diff --git a/api/v1alpha1/nutanix_clusterconfig_types.go b/api/v1alpha1/nutanix_clusterconfig_types.go index ec845b7b4..3d7ff29c8 100644 --- a/api/v1alpha1/nutanix_clusterconfig_types.go +++ b/api/v1alpha1/nutanix_clusterconfig_types.go @@ -9,7 +9,6 @@ import ( "strconv" corev1 "k8s.io/api/core/v1" - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" ) const ( @@ -20,14 +19,16 @@ const ( type NutanixSpec struct { // ControlPlaneEndpoint represents the endpoint used to communicate with the control plane. // host can be either DNS name or ip address - ControlPlaneEndpoint clusterv1.APIEndpoint `json:"controlPlaneEndpoint"` + ControlPlaneEndpoint ControlPlaneEndpointSpec `json:"controlPlaneEndpoint"` // Nutanix Prism Central endpoint configuration. PrismCentralEndpoint NutanixPrismCentralEndpointSpec `json:"prismCentralEndpoint"` } type NutanixPrismCentralEndpointSpec struct { - // The URL of Nutanix Prism Central, can be DNS name or an IP address + // The URL of Nutanix Prism Central, can be DNS name or an IP address. + // +kubebuilder:validation:Format=`uri` + // +kubebuilder:validation:Pattern=`^https://` URL string `json:"url"` // use insecure connection to Prism Central endpoint @@ -37,14 +38,15 @@ type NutanixPrismCentralEndpointSpec struct { // A base64 PEM encoded x509 cert for the RootCA that was used to create // the certificate for a Prism Central that uses certificates that were issued by a non-publicly trusted RootCA. // The trust bundle is added to the cert pool used to authenticate the TLS connection to the Prism Central. + // +kubebuilder:validation:Format=`byte` // +optional AdditionalTrustBundle *string `json:"additionalTrustBundle,omitempty"` - // A reference to the Secret for credential information for the target Prism Central instance - Credentials corev1.LocalObjectReference `json:"credentials"` + // A reference to the Secret for credential information for the target Prism Central instance. + Credentials *corev1.LocalObjectReference `json:"credentials"` } -//nolint:gocritic // no need for named return values +//nolint:gocritic // No need for named return values func (s NutanixPrismCentralEndpointSpec) ParseURL() (string, int32, error) { var prismCentralURL *url.URL prismCentralURL, err := url.Parse(s.URL) diff --git a/api/v1alpha1/nutanix_node_types.go b/api/v1alpha1/nutanix_node_types.go index 96d73377e..164afc5f3 100644 --- a/api/v1alpha1/nutanix_node_types.go +++ b/api/v1alpha1/nutanix_node_types.go @@ -57,6 +57,8 @@ type NutanixMachineDetails struct { type NutanixIdentifierType capxv1.NutanixIdentifierType // NutanixBootType is an enumeration of different boot types. +// +kubebuilder:validation:Required +// +kubebuilder:validation:Enum:=legacy;uefi type NutanixBootType capxv1.NutanixBootType type NutanixResourceIdentifier capxv1.NutanixResourceIdentifier diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index fdf550b04..2250faba0 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -556,7 +556,7 @@ func (in *DockerNodeSpec) DeepCopyInto(out *DockerNodeSpec) { *out = *in if in.CustomImage != nil { in, out := &in.CustomImage, &out.CustomImage - *out = new(OCIImage) + *out = new(string) **out = **in } } @@ -606,25 +606,6 @@ func (in *Etcd) DeepCopy() *Etcd { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in ExtraAPIServerCertSANs) DeepCopyInto(out *ExtraAPIServerCertSANs) { - { - in := &in - *out = make(ExtraAPIServerCertSANs, len(*in)) - copy(*out, *in) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExtraAPIServerCertSANs. -func (in ExtraAPIServerCertSANs) DeepCopy() ExtraAPIServerCertSANs { - if in == nil { - return nil - } - out := new(ExtraAPIServerCertSANs) - in.DeepCopyInto(out) - return *out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *GenericClusterConfig) DeepCopyInto(out *GenericClusterConfig) { *out = *in @@ -656,7 +637,7 @@ func (in *GenericClusterConfigSpec) DeepCopyInto(out *GenericClusterConfigSpec) *out = *in if in.KubernetesImageRepository != nil { in, out := &in.KubernetesImageRepository, &out.KubernetesImageRepository - *out = new(KubernetesImageRepository) + *out = new(string) **out = **in } if in.Etcd != nil { @@ -671,12 +652,12 @@ func (in *GenericClusterConfigSpec) DeepCopyInto(out *GenericClusterConfigSpec) } if in.ExtraAPIServerCertSANs != nil { in, out := &in.ExtraAPIServerCertSANs, &out.ExtraAPIServerCertSANs - *out = make(ExtraAPIServerCertSANs, len(*in)) + *out = make([]string, len(*in)) copy(*out, *in) } if in.ImageRegistries != nil { in, out := &in.ImageRegistries, &out.ImageRegistries - *out = make(ImageRegistries, len(*in)) + *out = make([]ImageRegistry, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -693,7 +674,7 @@ func (in *GenericClusterConfigSpec) DeepCopyInto(out *GenericClusterConfigSpec) } if in.Users != nil { in, out := &in.Users, &out.Users - *out = make(Users, len(*in)) + *out = make([]User, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -765,27 +746,6 @@ func (in *Image) DeepCopy() *Image { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in ImageRegistries) DeepCopyInto(out *ImageRegistries) { - { - in := &in - *out = make(ImageRegistries, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ImageRegistries. -func (in ImageRegistries) DeepCopy() ImageRegistries { - if in == nil { - return nil - } - out := new(ImageRegistries) - in.DeepCopyInto(out) - return *out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ImageRegistry) DeepCopyInto(out *ImageRegistry) { *out = *in @@ -994,7 +954,11 @@ func (in *NutanixPrismCentralEndpointSpec) DeepCopyInto(out *NutanixPrismCentral *out = new(string) **out = **in } - out.Credentials = in.Credentials + if in.Credentials != nil { + in, out := &in.Credentials, &out.Credentials + *out = new(v1.LocalObjectReference) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NutanixPrismCentralEndpointSpec. @@ -1215,27 +1179,6 @@ func (in *User) DeepCopy() *User { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in Users) DeepCopyInto(out *Users) { - { - in := &in - *out = make(Users, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Users. -func (in Users) DeepCopy() Users { - if in == nil { - return nil - } - out := new(Users) - in.DeepCopyInto(out) - return *out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *VPC) DeepCopyInto(out *VPC) { *out = *in diff --git a/pkg/handlers/docker/mutation/customimage/inject_control_plane.go b/pkg/handlers/docker/mutation/customimage/inject_control_plane.go index 2470eab6f..72f233f77 100644 --- a/pkg/handlers/docker/mutation/customimage/inject_control_plane.go +++ b/pkg/handlers/docker/mutation/customimage/inject_control_plane.go @@ -13,7 +13,6 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches/selectors" @@ -65,7 +64,7 @@ func (h *customImageControlPlanePatchHandler) Mutate( "holderRef", holderRef, ) - customImageVar, err := variables.Get[v1alpha1.OCIImage]( + customImageVar, err := variables.Get[string]( vars, h.variableName, h.variableFieldPath..., @@ -108,9 +107,7 @@ func (h *customImageControlPlanePatchHandler) Mutate( return err } - customImageVar = v1alpha1.OCIImage( - defaultKinDImageRepository + ":" + kubernetesVersion, - ) + customImageVar = defaultKinDImageRepository + ":" + kubernetesVersion } log.WithValues( @@ -119,7 +116,7 @@ func (h *customImageControlPlanePatchHandler) Mutate( "customImage", customImageVar, ).Info("setting customImage in control plane DockerMachineTemplate spec") - obj.Spec.Template.Spec.CustomImage = string(customImageVar) + obj.Spec.Template.Spec.CustomImage = customImageVar return nil }, diff --git a/pkg/handlers/docker/mutation/customimage/inject_worker.go b/pkg/handlers/docker/mutation/customimage/inject_worker.go index 9a5626e9a..98708b244 100644 --- a/pkg/handlers/docker/mutation/customimage/inject_worker.go +++ b/pkg/handlers/docker/mutation/customimage/inject_worker.go @@ -13,7 +13,6 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches/selectors" @@ -57,7 +56,7 @@ func (h *customImageWorkerPatchHandler) Mutate( "holderRef", holderRef, ) - customImageVar, err := variables.Get[v1alpha1.OCIImage]( + customImageVar, err := variables.Get[string]( vars, h.variableName, h.variableFieldPath..., @@ -100,9 +99,7 @@ func (h *customImageWorkerPatchHandler) Mutate( return err } - customImageVar = v1alpha1.OCIImage( - defaultKinDImageRepository + ":" + kubernetesVersion, - ) + customImageVar = defaultKinDImageRepository + ":" + kubernetesVersion } log.WithValues( @@ -111,7 +108,7 @@ func (h *customImageWorkerPatchHandler) Mutate( "customImage", customImageVar, ).Info("setting customImage in workers DockerMachineTemplate spec") - obj.Spec.Template.Spec.CustomImage = string(customImageVar) + obj.Spec.Template.Spec.CustomImage = customImageVar return nil }, diff --git a/pkg/handlers/docker/mutation/customimage/variables_test.go b/pkg/handlers/docker/mutation/customimage/variables_test.go index e965d9f68..0362aa6f4 100644 --- a/pkg/handlers/docker/mutation/customimage/variables_test.go +++ b/pkg/handlers/docker/mutation/customimage/variables_test.go @@ -26,7 +26,7 @@ func TestVariableValidation(t *testing.T) { Vals: v1alpha1.DockerClusterConfigSpec{ ControlPlane: &v1alpha1.DockerNodeConfigSpec{ Docker: &v1alpha1.DockerNodeSpec{ - CustomImage: ptr.To(v1alpha1.OCIImage("docker.io/some/image:v2.3.4")), + CustomImage: ptr.To("docker.io/some/image:v2.3.4"), }, }, }, @@ -36,7 +36,7 @@ func TestVariableValidation(t *testing.T) { Vals: v1alpha1.DockerClusterConfigSpec{ ControlPlane: &v1alpha1.DockerNodeConfigSpec{ Docker: &v1alpha1.DockerNodeSpec{ - CustomImage: ptr.To(v1alpha1.OCIImage("this.is.not.valid?")), + CustomImage: ptr.To("this.is.not.valid?"), }, }, }, diff --git a/pkg/handlers/generic/clusterconfig/variables_test.go b/pkg/handlers/generic/clusterconfig/variables_test.go index 8c7639911..e5c9d3bb9 100644 --- a/pkg/handlers/generic/clusterconfig/variables_test.go +++ b/pkg/handlers/generic/clusterconfig/variables_test.go @@ -27,7 +27,7 @@ func TestVariableValidation(t *testing.T) { HTTPS: "https://a.b.c.example.com", AdditionalNo: []string{"d.e.f.example.com"}, }, - ExtraAPIServerCertSANs: v1alpha1.ExtraAPIServerCertSANs{"a.b.c.example.com"}, + ExtraAPIServerCertSANs: []string{"a.b.c.example.com"}, }, }, ) diff --git a/pkg/handlers/generic/mutation/extraapiservercertsans/inject.go b/pkg/handlers/generic/mutation/extraapiservercertsans/inject.go index 9e9c4f0fa..09f912839 100644 --- a/pkg/handlers/generic/mutation/extraapiservercertsans/inject.go +++ b/pkg/handlers/generic/mutation/extraapiservercertsans/inject.go @@ -60,7 +60,7 @@ func (h *extraAPIServerCertSANsPatchHandler) Mutate( log := ctrl.LoggerFrom(ctx).WithValues( "holderRef", holderRef, ) - extraAPIServerCertSANsVar, err := variables.Get[v1alpha1.ExtraAPIServerCertSANs]( + extraAPIServerCertSANsVar, err := variables.Get[[]string]( vars, h.variableName, h.variableFieldPath..., diff --git a/pkg/handlers/generic/mutation/extraapiservercertsans/inject_test.go b/pkg/handlers/generic/mutation/extraapiservercertsans/inject_test.go index 2204cb59d..b7ba69991 100644 --- a/pkg/handlers/generic/mutation/extraapiservercertsans/inject_test.go +++ b/pkg/handlers/generic/mutation/extraapiservercertsans/inject_test.go @@ -53,7 +53,7 @@ var _ = Describe("Generate Extra API server certificate patches", func() { clusterconfig.MetaVariableName, v1alpha1.AWSClusterConfigSpec{ GenericClusterConfigSpec: v1alpha1.GenericClusterConfigSpec{ - ExtraAPIServerCertSANs: v1alpha1.ExtraAPIServerCertSANs{ + ExtraAPIServerCertSANs: []string{ "a.b.c.example.com", "a.b.c.example.com", "d.e.f.example.com", @@ -93,7 +93,7 @@ var _ = Describe("Generate Extra API server certificate patches", func() { capitest.VariableWithValue( clusterconfig.MetaVariableName, v1alpha1.GenericClusterConfigSpec{ - ExtraAPIServerCertSANs: v1alpha1.ExtraAPIServerCertSANs{ + ExtraAPIServerCertSANs: []string{ "a.b.c.example.com", }, }, @@ -135,7 +135,7 @@ var _ = Describe("Generate Extra API server certificate patches", func() { capitest.VariableWithValue( clusterconfig.MetaVariableName, v1alpha1.GenericClusterConfigSpec{ - ExtraAPIServerCertSANs: v1alpha1.ExtraAPIServerCertSANs{ + ExtraAPIServerCertSANs: []string{ "a.b.c.example.com", }, }, diff --git a/pkg/handlers/generic/mutation/extraapiservercertsans/variables_test.go b/pkg/handlers/generic/mutation/extraapiservercertsans/variables_test.go index cf737e168..1ac50a83c 100644 --- a/pkg/handlers/generic/mutation/extraapiservercertsans/variables_test.go +++ b/pkg/handlers/generic/mutation/extraapiservercertsans/variables_test.go @@ -23,20 +23,20 @@ func TestVariableValidation(t *testing.T) { capitest.VariableTestDef{ Name: "single valid SAN", Vals: v1alpha1.GenericClusterConfigSpec{ - ExtraAPIServerCertSANs: v1alpha1.ExtraAPIServerCertSANs{"a.b.c.example.com"}, + ExtraAPIServerCertSANs: []string{"a.b.c.example.com"}, }, }, capitest.VariableTestDef{ Name: "single invalid SAN", Vals: v1alpha1.GenericClusterConfigSpec{ - ExtraAPIServerCertSANs: v1alpha1.ExtraAPIServerCertSANs{"invalid:san"}, + ExtraAPIServerCertSANs: []string{"invalid:san"}, }, ExpectError: true, }, capitest.VariableTestDef{ Name: "duplicate valid SANs", Vals: v1alpha1.GenericClusterConfigSpec{ - ExtraAPIServerCertSANs: v1alpha1.ExtraAPIServerCertSANs{ + ExtraAPIServerCertSANs: []string{ "a.b.c.example.com", "a.b.c.example.com", }, diff --git a/pkg/handlers/generic/mutation/imageregistries/credentials/inject.go b/pkg/handlers/generic/mutation/imageregistries/credentials/inject.go index a314bb99d..5ef9832a7 100644 --- a/pkg/handlers/generic/mutation/imageregistries/credentials/inject.go +++ b/pkg/handlers/generic/mutation/imageregistries/credentials/inject.go @@ -75,7 +75,7 @@ func (h *imageRegistriesPatchHandler) Mutate( "holderRef", holderRef, ) - imageRegistries, imageRegistriesErr := variables.Get[v1alpha1.ImageRegistries]( + imageRegistries, imageRegistriesErr := variables.Get[[]v1alpha1.ImageRegistry]( vars, h.variableName, h.variableFieldPath..., diff --git a/pkg/handlers/generic/mutation/imageregistries/credentials/inject_test.go b/pkg/handlers/generic/mutation/imageregistries/credentials/inject_test.go index 91bdf9971..38cb57081 100644 --- a/pkg/handlers/generic/mutation/imageregistries/credentials/inject_test.go +++ b/pkg/handlers/generic/mutation/imageregistries/credentials/inject_test.go @@ -148,11 +148,9 @@ var _ = Describe("Generate Image registry patches", func() { Vars: []runtimehooksv1.Variable{ capitest.VariableWithValue( clusterconfig.MetaVariableName, - v1alpha1.ImageRegistries{ - v1alpha1.ImageRegistry{ - URL: "https://123456789.dkr.ecr.us-east-1.amazonaws.com", - }, - }, + []v1alpha1.ImageRegistry{{ + URL: "https://123456789.dkr.ecr.us-east-1.amazonaws.com", + }}, imageregistries.VariableName, ), }, @@ -203,16 +201,14 @@ var _ = Describe("Generate Image registry patches", func() { Vars: []runtimehooksv1.Variable{ capitest.VariableWithValue( clusterconfig.MetaVariableName, - v1alpha1.ImageRegistries{ - v1alpha1.ImageRegistry{ - URL: "https://registry.example.com", - Credentials: &v1alpha1.RegistryCredentials{ - SecretRef: &corev1.LocalObjectReference{ - Name: validSecretName, - }, + []v1alpha1.ImageRegistry{{ + URL: "https://registry.example.com", + Credentials: &v1alpha1.RegistryCredentials{ + SecretRef: &corev1.LocalObjectReference{ + Name: validSecretName, }, }, - }, + }}, imageregistries.VariableName, ), }, @@ -269,11 +265,9 @@ var _ = Describe("Generate Image registry patches", func() { Vars: []runtimehooksv1.Variable{ capitest.VariableWithValue( clusterconfig.MetaVariableName, - v1alpha1.ImageRegistries{ - v1alpha1.ImageRegistry{ - URL: "https://123456789.dkr.ecr.us-east-1.amazonaws.com", - }, - }, + []v1alpha1.ImageRegistry{{ + URL: "https://123456789.dkr.ecr.us-east-1.amazonaws.com", + }}, imageregistries.VariableName, ), capitest.VariableWithValue( @@ -324,16 +318,14 @@ var _ = Describe("Generate Image registry patches", func() { Vars: []runtimehooksv1.Variable{ capitest.VariableWithValue( clusterconfig.MetaVariableName, - v1alpha1.ImageRegistries{ - v1alpha1.ImageRegistry{ - URL: "https://registry.example.com", - Credentials: &v1alpha1.RegistryCredentials{ - SecretRef: &corev1.LocalObjectReference{ - Name: validSecretName, - }, + []v1alpha1.ImageRegistry{{ + URL: "https://registry.example.com", + Credentials: &v1alpha1.RegistryCredentials{ + SecretRef: &corev1.LocalObjectReference{ + Name: validSecretName, }, }, - }, + }}, imageregistries.VariableName, ), capitest.VariableWithValue( @@ -387,11 +379,9 @@ var _ = Describe("Generate Image registry patches", func() { Vars: []runtimehooksv1.Variable{ capitest.VariableWithValue( clusterconfig.MetaVariableName, - v1alpha1.ImageRegistries{ - v1alpha1.ImageRegistry{ - URL: "https://registry.example.com", - }, - }, + []v1alpha1.ImageRegistry{{ + URL: "https://registry.example.com", + }}, imageregistries.VariableName, ), }, diff --git a/pkg/handlers/generic/mutation/kubernetesimagerepository/inject.go b/pkg/handlers/generic/mutation/kubernetesimagerepository/inject.go index a7d08e8af..3baceeff5 100644 --- a/pkg/handlers/generic/mutation/kubernetesimagerepository/inject.go +++ b/pkg/handlers/generic/mutation/kubernetesimagerepository/inject.go @@ -14,7 +14,6 @@ import ( ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/patches/selectors" @@ -58,7 +57,7 @@ func (h *imageRepositoryPatchHandler) Mutate( "holderRef", holderRef, ) - imageRepositoryVar, err := variables.Get[v1alpha1.KubernetesImageRepository]( + imageRepositoryVar, err := variables.Get[string]( vars, h.variableName, h.variableFieldPath..., @@ -91,7 +90,7 @@ func (h *imageRepositoryPatchHandler) Mutate( if obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration == nil { obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration = &bootstrapv1.ClusterConfiguration{} } - obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration.ImageRepository = imageRepositoryVar.String() + obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration.ImageRepository = imageRepositoryVar return nil }, diff --git a/pkg/handlers/generic/mutation/kubernetesimagerepository/inject_test.go b/pkg/handlers/generic/mutation/kubernetesimagerepository/inject_test.go index 7c19e02ba..d31908868 100644 --- a/pkg/handlers/generic/mutation/kubernetesimagerepository/inject_test.go +++ b/pkg/handlers/generic/mutation/kubernetesimagerepository/inject_test.go @@ -10,7 +10,6 @@ import ( "github.com/onsi/gomega" runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request" @@ -37,7 +36,7 @@ var _ = Describe("Generate Kubernetes Image Repository patches", func() { Vars: []runtimehooksv1.Variable{ capitest.VariableWithValue( clusterconfig.MetaVariableName, - v1alpha1.KubernetesImageRepository("my-registry.io/my-org/my-repo"), + "my-registry.io/my-org/my-repo", VariableName, ), }, diff --git a/pkg/handlers/generic/mutation/kubernetesimagerepository/variables_test.go b/pkg/handlers/generic/mutation/kubernetesimagerepository/variables_test.go index 970617b2a..83d39368d 100644 --- a/pkg/handlers/generic/mutation/kubernetesimagerepository/variables_test.go +++ b/pkg/handlers/generic/mutation/kubernetesimagerepository/variables_test.go @@ -25,7 +25,7 @@ func TestVariableValidation(t *testing.T) { Name: "set", Vals: v1alpha1.GenericClusterConfigSpec{ KubernetesImageRepository: ptr.To( - v1alpha1.KubernetesImageRepository("my-registry.io/my-org/my-repo"), + "my-registry.io/my-org/my-repo", ), }, }, diff --git a/pkg/handlers/generic/mutation/users/inject.go b/pkg/handlers/generic/mutation/users/inject.go index 4891efee4..7ac2129cb 100644 --- a/pkg/handlers/generic/mutation/users/inject.go +++ b/pkg/handlers/generic/mutation/users/inject.go @@ -59,7 +59,7 @@ func (h *usersPatchHandler) Mutate( ) error { log := ctrl.LoggerFrom(ctx, "holderRef", holderRef) - usersVariable, err := variables.Get[v1alpha1.Users]( + usersVariable, err := variables.Get[[]v1alpha1.User]( vars, h.variableName, h.variableFieldPath..., diff --git a/pkg/handlers/nutanix/mutation/controlplaneendpoint/inject_test.go b/pkg/handlers/nutanix/mutation/controlplaneendpoint/inject_test.go index 15356cc81..30c61ceb8 100644 --- a/pkg/handlers/nutanix/mutation/controlplaneendpoint/inject_test.go +++ b/pkg/handlers/nutanix/mutation/controlplaneendpoint/inject_test.go @@ -8,9 +8,9 @@ import ( . "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" + "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request" @@ -38,7 +38,7 @@ var _ = Describe("Generate Nutanix ControlPlane endpoint patches", func() { Vars: []runtimehooksv1.Variable{ capitest.VariableWithValue( clusterconfig.MetaVariableName, - clusterv1.APIEndpoint{ + v1alpha1.ControlPlaneEndpointSpec{ Host: "10.20.100.10", Port: 6443, }, diff --git a/pkg/handlers/nutanix/mutation/controlplaneendpoint/variables_test.go b/pkg/handlers/nutanix/mutation/controlplaneendpoint/variables_test.go index f73d11a76..92fa0c8df 100644 --- a/pkg/handlers/nutanix/mutation/controlplaneendpoint/variables_test.go +++ b/pkg/handlers/nutanix/mutation/controlplaneendpoint/variables_test.go @@ -9,7 +9,6 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/utils/ptr" - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest" @@ -33,14 +32,14 @@ func TestVariableValidation(t *testing.T) { Name: "valid host and port", Vals: v1alpha1.NutanixClusterConfigSpec{ Nutanix: &v1alpha1.NutanixSpec{ - ControlPlaneEndpoint: clusterv1.APIEndpoint{ + ControlPlaneEndpoint: v1alpha1.ControlPlaneEndpointSpec{ Host: "10.20.100.10", Port: 6443, }, // PrismCentralEndpoint is a required field and must always be set PrismCentralEndpoint: v1alpha1.NutanixPrismCentralEndpointSpec{ URL: testPrismCentralURL, - Credentials: corev1.LocalObjectReference{ + Credentials: &corev1.LocalObjectReference{ Name: "credentials", }, }, @@ -51,14 +50,14 @@ func TestVariableValidation(t *testing.T) { Name: "empty host", Vals: v1alpha1.NutanixClusterConfigSpec{ Nutanix: &v1alpha1.NutanixSpec{ - ControlPlaneEndpoint: clusterv1.APIEndpoint{ + ControlPlaneEndpoint: v1alpha1.ControlPlaneEndpointSpec{ Host: "", Port: 6443, }, // PrismCentralEndpoint is a required field and must always be set PrismCentralEndpoint: v1alpha1.NutanixPrismCentralEndpointSpec{ URL: testPrismCentralURL, - Credentials: corev1.LocalObjectReference{ + Credentials: &corev1.LocalObjectReference{ Name: "credentials", }, }, @@ -70,14 +69,14 @@ func TestVariableValidation(t *testing.T) { Name: "port set to 0", Vals: v1alpha1.NutanixClusterConfigSpec{ Nutanix: &v1alpha1.NutanixSpec{ - ControlPlaneEndpoint: clusterv1.APIEndpoint{ + ControlPlaneEndpoint: v1alpha1.ControlPlaneEndpointSpec{ Host: "10.20.100.10", Port: 0, }, // PrismCentralEndpoint is a required field and must always be set PrismCentralEndpoint: v1alpha1.NutanixPrismCentralEndpointSpec{ URL: testPrismCentralURL, - Credentials: corev1.LocalObjectReference{ + Credentials: &corev1.LocalObjectReference{ Name: "credentials", }, }, diff --git a/pkg/handlers/nutanix/mutation/prismcentralendpoint/inject_test.go b/pkg/handlers/nutanix/mutation/prismcentralendpoint/inject_test.go index d270994d3..3b0f00ea0 100644 --- a/pkg/handlers/nutanix/mutation/prismcentralendpoint/inject_test.go +++ b/pkg/handlers/nutanix/mutation/prismcentralendpoint/inject_test.go @@ -47,7 +47,7 @@ var _ = Describe("Generate Nutanix Prism Central Endpoint patches", func() { v1alpha1.NutanixPrismCentralEndpointSpec{ URL: "https://prism-central.nutanix.com:9441", Insecure: true, - Credentials: corev1.LocalObjectReference{ + Credentials: &corev1.LocalObjectReference{ Name: "credentials", }, }, @@ -81,7 +81,7 @@ var _ = Describe("Generate Nutanix Prism Central Endpoint patches", func() { v1alpha1.NutanixPrismCentralEndpointSpec{ URL: "https://prism-central.nutanix.com", Insecure: true, - Credentials: corev1.LocalObjectReference{ + Credentials: &corev1.LocalObjectReference{ Name: "credentials", }, }, @@ -118,7 +118,7 @@ var _ = Describe("Generate Nutanix Prism Central Endpoint patches", func() { v1alpha1.NutanixPrismCentralEndpointSpec{ URL: "https://prism-central.nutanix.com:9441", Insecure: true, - Credentials: corev1.LocalObjectReference{ + Credentials: &corev1.LocalObjectReference{ Name: "credentials", }, AdditionalTrustBundle: ptr.To(testCertBundle), diff --git a/pkg/handlers/nutanix/mutation/prismcentralendpoint/variables_test.go b/pkg/handlers/nutanix/mutation/prismcentralendpoint/variables_test.go index c7d50c79c..3590c624f 100644 --- a/pkg/handlers/nutanix/mutation/prismcentralendpoint/variables_test.go +++ b/pkg/handlers/nutanix/mutation/prismcentralendpoint/variables_test.go @@ -9,7 +9,6 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/utils/ptr" - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest" @@ -34,12 +33,12 @@ func TestVariableValidation(t *testing.T) { v1alpha1.DefaultPrismCentralPort, ), Insecure: false, - Credentials: corev1.LocalObjectReference{ + Credentials: &corev1.LocalObjectReference{ Name: "credentials", }, }, // ControlPlaneEndpoint is a required field and must always be set - ControlPlaneEndpoint: clusterv1.APIEndpoint{ + ControlPlaneEndpoint: v1alpha1.ControlPlaneEndpointSpec{ Host: "10.20.100.10", Port: 6443, }, @@ -56,12 +55,12 @@ func TestVariableValidation(t *testing.T) { v1alpha1.DefaultPrismCentralPort, ), Insecure: false, - Credentials: corev1.LocalObjectReference{ + Credentials: &corev1.LocalObjectReference{ Name: "credentials", }, }, // ControlPlaneEndpoint is a required field and must always be set - ControlPlaneEndpoint: clusterv1.APIEndpoint{ + ControlPlaneEndpoint: v1alpha1.ControlPlaneEndpointSpec{ Host: "10.20.100.10", Port: 6443, }, @@ -75,12 +74,12 @@ func TestVariableValidation(t *testing.T) { PrismCentralEndpoint: v1alpha1.NutanixPrismCentralEndpointSpec{ URL: "https://prism-central.nutanix.com", Insecure: false, - Credentials: corev1.LocalObjectReference{ + Credentials: &corev1.LocalObjectReference{ Name: "credentials", }, }, // ControlPlaneEndpoint is a required field and must always be set - ControlPlaneEndpoint: clusterv1.APIEndpoint{ + ControlPlaneEndpoint: v1alpha1.ControlPlaneEndpointSpec{ Host: "10.20.100.10", Port: 6443, }, @@ -93,12 +92,12 @@ func TestVariableValidation(t *testing.T) { Nutanix: &v1alpha1.NutanixSpec{ PrismCentralEndpoint: v1alpha1.NutanixPrismCentralEndpointSpec{ Insecure: false, - Credentials: corev1.LocalObjectReference{ + Credentials: &corev1.LocalObjectReference{ Name: "credentials", }, }, // ControlPlaneEndpoint is a required field and must always be set - ControlPlaneEndpoint: clusterv1.APIEndpoint{ + ControlPlaneEndpoint: v1alpha1.ControlPlaneEndpointSpec{ Host: "10.20.100.10", Port: 6443, }, @@ -113,12 +112,12 @@ func TestVariableValidation(t *testing.T) { PrismCentralEndpoint: v1alpha1.NutanixPrismCentralEndpointSpec{ URL: "http://prism-central.nutanix.com", Insecure: false, - Credentials: corev1.LocalObjectReference{ + Credentials: &corev1.LocalObjectReference{ Name: "credentials", }, }, // ControlPlaneEndpoint is a required field and must always be set - ControlPlaneEndpoint: clusterv1.APIEndpoint{ + ControlPlaneEndpoint: v1alpha1.ControlPlaneEndpointSpec{ Host: "10.20.100.10", Port: 6443, }, @@ -133,12 +132,12 @@ func TestVariableValidation(t *testing.T) { PrismCentralEndpoint: v1alpha1.NutanixPrismCentralEndpointSpec{ URL: "not-a-valid-url", Insecure: false, - Credentials: corev1.LocalObjectReference{ + Credentials: &corev1.LocalObjectReference{ Name: "credentials", }, }, // ControlPlaneEndpoint is a required field and must always be set - ControlPlaneEndpoint: clusterv1.APIEndpoint{ + ControlPlaneEndpoint: v1alpha1.ControlPlaneEndpointSpec{ Host: "10.20.100.10", Port: 6443, }, @@ -158,7 +157,7 @@ func TestVariableValidation(t *testing.T) { Insecure: false, }, // ControlPlaneEndpoint is a required field and must always be set - ControlPlaneEndpoint: clusterv1.APIEndpoint{ + ControlPlaneEndpoint: v1alpha1.ControlPlaneEndpointSpec{ Host: "10.20.100.10", Port: 6443, }, From b35f95539889641ab603a4a418e05ea9befbee12 Mon Sep 17 00:00:00 2001 From: Jimmi Dyson Date: Thu, 18 Apr 2024 21:06:17 +0100 Subject: [PATCH 3/6] fix: Remove generic cluster config variable This was never used anywhere. --- api/v1alpha1/clusterconfig_types.go | 52 ++- .../caren.nutanix.com_awsclusterconfigs.yaml | 6 +- ...aren.nutanix.com_dockerclusterconfigs.yaml | 9 +- ...ren.nutanix.com_genericclusterconfigs.yaml | 352 ------------------ ...ren.nutanix.com_nutanixclusterconfigs.yaml | 6 +- api/v1alpha1/zz_generated.deepcopy.go | 46 +-- .../generic/clusterconfig/variables.go | 39 -- .../generic/clusterconfig/variables_test.go | 34 -- .../clusterautoscaler/variables_test.go | 93 ++++- .../generic/lifecycle/cni/variables_test.go | 114 +++--- .../generic/lifecycle/nfd/variables_test.go | 89 +++-- .../generic/mutation/etcd/variables_test.go | 104 ++++-- .../extraapiservercertsans/inject_test.go | 14 +- .../extraapiservercertsans/variables_test.go | 89 ++++- .../mutation/httpproxy/variables_test.go | 56 ++- .../credentials/variables_test.go | 125 ++++--- .../variables_test.go | 52 ++- .../mutation/mirrors/variables_test.go | 104 ++++-- .../generic/mutation/users/variables_test.go | 73 ++-- 19 files changed, 682 insertions(+), 775 deletions(-) delete mode 100644 api/v1alpha1/crds/caren.nutanix.com_genericclusterconfigs.yaml delete mode 100644 pkg/handlers/generic/clusterconfig/variables_test.go diff --git a/api/v1alpha1/clusterconfig_types.go b/api/v1alpha1/clusterconfig_types.go index 573262ff4..5710246c1 100644 --- a/api/v1alpha1/clusterconfig_types.go +++ b/api/v1alpha1/clusterconfig_types.go @@ -42,8 +42,6 @@ var ( "0.0.0.0", } - //go:embed crds/caren.nutanix.com_genericclusterconfigs.yaml - genericClusterConfigCRDDefinition []byte //go:embed crds/caren.nutanix.com_dockerclusterconfigs.yaml dockerClusterConfigCRDDefinition []byte //go:embed crds/caren.nutanix.com_awsclusterconfigs.yaml @@ -51,9 +49,6 @@ var ( //go:embed crds/caren.nutanix.com_nutanixclusterconfigs.yaml nutanixClusterConfigCRDDefinition []byte - genericClusterConfigVariableSchema = variables.MustSchemaFromCRDYAML( - genericClusterConfigCRDDefinition, - ) dockerClusterConfigVariableSchema = variables.MustSchemaFromCRDYAML( dockerClusterConfigCRDDefinition, ) @@ -90,6 +85,12 @@ type AWSClusterConfigSpec struct { // +optional ControlPlane *AWSNodeConfigSpec `json:"controlPlane,omitempty"` + + // Extra Subject Alternative Names for the API Server signing cert. + // +kubebuilder:validation:UniqueItems=true + // +kubebuilder:validation:items:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$` + // +optional + ExtraAPIServerCertSANs []string `json:"extraAPIServerCertSANs,omitempty"` } // +kubebuilder:object:root=true @@ -116,6 +117,17 @@ type DockerClusterConfigSpec struct { // +optional ControlPlane *DockerNodeConfigSpec `json:"controlPlane,omitempty"` + + // Extra Subject Alternative Names for the API Server signing cert. + // For the Nutanix provider, the following default SANs will always be added: + // - localhost + // - 127.0.0.1 + // - 0.0.0.0 + // - host.docker.internal + // +kubebuilder:validation:UniqueItems=true + // +kubebuilder:validation:items:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$` + // +optional + ExtraAPIServerCertSANs []string `json:"extraAPIServerCertSANs,omitempty"` } // +kubebuilder:object:root=true @@ -142,21 +154,16 @@ type NutanixClusterConfigSpec struct { // +optional ControlPlane *NutanixNodeConfigSpec `json:"controlPlane,omitempty"` -} - -// +kubebuilder:object:root=true - -// GenericClusterConfig is the Schema for the clusterconfigs API. -type GenericClusterConfig struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata,omitempty"` + // Subject Alternative Names for the API Server signing cert. + // For the Nutanix provider, the following default SANs will always be added: + // - localhost + // - 127.0.0.1 + // - 0.0.0.0 + // +kubebuilder:validation:UniqueItems=true + // +kubebuilder:validation:items:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$` // +optional - Spec GenericClusterConfigSpec `json:"spec,omitempty"` -} - -func (s GenericClusterConfig) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect. - return genericClusterConfigVariableSchema + ExtraAPIServerCertSANs []string `json:"extraAPIServerCertSANs,omitempty"` } // GenericClusterConfigSpec defines the desired state of GenericClusterConfig. @@ -172,14 +179,6 @@ type GenericClusterConfigSpec struct { // +optional Proxy *HTTPProxy `json:"proxy,omitempty"` - // Subject Alternative Names for the API Server signing cert. - // For Docker are injected automatically. - // For Nutanix are injected automatically. - // +kubebuilder:validation:UniqueItems=true - // +kubebuilder:validation:items:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$` - // +optional - ExtraAPIServerCertSANs []string `json:"extraAPIServerCertSANs,omitempty"` - // +optional ImageRegistries []ImageRegistry `json:"imageRegistries,omitempty"` @@ -287,6 +286,5 @@ func init() { &AWSClusterConfig{}, &DockerClusterConfig{}, &NutanixClusterConfig{}, - &GenericClusterConfig{}, ) } diff --git a/api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml index 2372df367..d31bed946 100644 --- a/api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml +++ b/api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml @@ -308,10 +308,8 @@ spec: type: object type: object extraAPIServerCertSANs: - description: |- - Subject Alternative Names for the API Server signing cert. - For Docker are injected automatically. - For Nutanix are injected automatically. + description: Extra Subject Alternative Names for the API Server signing + cert. items: pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ type: string diff --git a/api/v1alpha1/crds/caren.nutanix.com_dockerclusterconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_dockerclusterconfigs.yaml index c6aca6fb7..0086d1894 100644 --- a/api/v1alpha1/crds/caren.nutanix.com_dockerclusterconfigs.yaml +++ b/api/v1alpha1/crds/caren.nutanix.com_dockerclusterconfigs.yaml @@ -235,9 +235,12 @@ spec: type: object extraAPIServerCertSANs: description: |- - Subject Alternative Names for the API Server signing cert. - For Docker are injected automatically. - For Nutanix are injected automatically. + Extra Subject Alternative Names for the API Server signing cert. + For the Nutanix provider, the following default SANs will always be added: + - localhost + - 127.0.0.1 + - 0.0.0.0 + - host.docker.internal items: pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ type: string diff --git a/api/v1alpha1/crds/caren.nutanix.com_genericclusterconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_genericclusterconfigs.yaml deleted file mode 100644 index 0042f5cea..000000000 --- a/api/v1alpha1/crds/caren.nutanix.com_genericclusterconfigs.yaml +++ /dev/null @@ -1,352 +0,0 @@ -# Copyright 2023 D2iQ, Inc. All rights reserved. -# SPDX-License-Identifier: Apache-2.0 ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: (devel) - name: genericclusterconfigs.caren.nutanix.com -spec: - group: caren.nutanix.com - names: - kind: GenericClusterConfig - listKind: GenericClusterConfigList - plural: genericclusterconfigs - singular: genericclusterconfig - scope: Namespaced - versions: - - name: v1alpha1 - schema: - openAPIV3Schema: - description: GenericClusterConfig is the Schema for the clusterconfigs API. - properties: - apiVersion: - description: |- - APIVersion defines the versioned schema of this representation of an object. - Servers should convert recognized schemas to the latest internal value, and - may reject unrecognized values. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources - type: string - kind: - description: |- - Kind is a string value representing the REST resource this object represents. - Servers may infer this from the endpoint the client submits requests to. - Cannot be updated. - In CamelCase. - More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds - type: string - metadata: - type: object - spec: - description: GenericClusterConfigSpec defines the desired state of GenericClusterConfig. - properties: - addons: - properties: - ccm: - description: CCM tells us to enable or disable the cloud provider - interface. - properties: - credentials: - description: A reference to the Secret for credential information - for the target Prism Central instance - properties: - name: - description: |- - Name of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names - TODO: Add other useful fields. apiVersion, kind, uid? - type: string - type: object - x-kubernetes-map-type: atomic - type: object - clusterAutoscaler: - description: ClusterAutoscaler tells us to enable or disable the - cluster-autoscaler addon. - properties: - strategy: - description: |- - Addon strategy used to deploy cluster-autoscaler to the management cluster - targeting the workload cluster. - enum: - - ClusterResourceSet - - HelmAddon - type: string - required: - - strategy - type: object - cni: - description: CNI required for providing CNI configuration. - properties: - provider: - description: CNI provider to deploy. - enum: - - Calico - - Cilium - type: string - strategy: - description: Addon strategy used to deploy the CNI provider - to the workload cluster. - enum: - - ClusterResourceSet - - HelmAddon - type: string - required: - - provider - - strategy - type: object - csi: - properties: - defaultStorage: - properties: - providerName: - description: Name of the CSI Provider for the default - storage class. - enum: - - aws-ebs - - nutanix - type: string - storageClassConfigName: - description: Name of storage class config in any of the - provider objects. - type: string - required: - - providerName - - storageClassConfigName - type: object - providers: - items: - properties: - credentials: - description: The reference to any secret used by the - CSI Provider. - properties: - name: - description: |- - Name of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names - TODO: Add other useful fields. apiVersion, kind, uid? - type: string - type: object - x-kubernetes-map-type: atomic - name: - description: Name of the CSI Provider. - enum: - - aws-ebs - - nutanix - type: string - storageClassConfig: - items: - properties: - allowExpansion: - default: false - description: If the storage class should allow - volume expanding - type: boolean - name: - description: Name of storage class config. - type: string - parameters: - additionalProperties: - type: string - description: Parameters passed into the storage - class object. - type: object - reclaimPolicy: - default: Delete - description: PersistentVolumeReclaimPolicy describes - a policy for end-of-life maintenance of persistent - volumes. - enum: - - Delete - - Retain - - Recycle - type: string - volumeBindingMode: - default: WaitForFirstConsumer - description: VolumeBindingMode indicates how PersistentVolumeClaims - should be bound. - enum: - - Immediate - - WaitForFirstConsumer - type: string - required: - - name - type: object - type: array - strategy: - description: Addon strategy used to deploy the CSI provider - to the workload cluster. - enum: - - ClusterResourceSet - - HelmAddon - type: string - required: - - name - - strategy - type: object - type: array - type: object - nfd: - description: NFD tells us to enable or disable the node feature - discovery addon. - properties: - strategy: - description: Addon strategy used to deploy Node Feature Discovery - (NFD) to the workload cluster. - enum: - - ClusterResourceSet - - HelmAddon - type: string - required: - - strategy - type: object - type: object - etcd: - properties: - image: - description: Image required for overriding etcd image details. - properties: - repository: - description: Repository is used to override the image repository - to pull from. - pattern: ^((?:[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*|\[(?:[a-fA-F0-9:]+)\])(:[0-9]+)?/)?[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*(/[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*)*$ - type: string - tag: - description: Tag is used to override the default image tag. - pattern: ^[\w][\w.-]{0,127}$ - type: string - type: object - type: object - extraAPIServerCertSANs: - description: |- - Subject Alternative Names for the API Server signing cert. - For Docker are injected automatically. - For Nutanix are injected automatically. - items: - pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ - type: string - type: array - uniqueItems: true - globalImageRegistryMirror: - description: GlobalImageRegistryMirror sets default mirror configuration - for all the image registries. - properties: - credentials: - description: Credentials and CA certificate for the image registry - mirror - properties: - secretRef: - description: |- - A reference to the Secret containing the registry credentials and optional CA certificate - using the keys `username`, `password` and `ca.crt`. - This credentials Secret is not required for some registries, e.g. ECR. - properties: - name: - description: |- - Name of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names - TODO: Add other useful fields. apiVersion, kind, uid? - type: string - type: object - x-kubernetes-map-type: atomic - type: object - url: - description: Registry mirror URL. - format: uri - pattern: ^https?:// - type: string - required: - - url - type: object - imageRegistries: - items: - properties: - credentials: - description: Credentials and CA certificate for the image registry - properties: - secretRef: - description: |- - A reference to the Secret containing the registry credentials and optional CA certificate - using the keys `username`, `password` and `ca.crt`. - This credentials Secret is not required for some registries, e.g. ECR. - properties: - name: - description: |- - Name of the referent. - More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names - TODO: Add other useful fields. apiVersion, kind, uid? - type: string - type: object - x-kubernetes-map-type: atomic - type: object - url: - description: Registry URL. - format: uri - pattern: ^https?:// - type: string - required: - - url - type: object - type: array - kubernetesImageRepository: - description: Sets the Kubernetes image repository used for the KubeadmControlPlane. - pattern: ^((?:[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*|\[(?:[a-fA-F0-9:]+)\])(:[0-9]+)?/)?[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*(/[a-z0-9]+((?:[._]|__|[-]+)[a-z0-9]+)*)*$ - type: string - proxy: - description: HTTPProxy required for providing proxy configuration. - properties: - additionalNo: - description: |- - AdditionalNo Proxy list that will be added to the automatically calculated - values that will apply no_proxy configuration for cluster internal network. - Default values: localhost,127.0.0.1,,,kubernetes - ,kubernetes.default,.svc,.svc. - items: - type: string - type: array - http: - description: HTTP proxy value. - type: string - https: - description: HTTPS proxy value. - type: string - required: - - additionalNo - type: object - users: - items: - description: User defines the input for a generated user in cloud-init. - properties: - hashedPassword: - description: |- - HashedPassword is a hashed password for the user, formatted as described - by the crypt(5) man page. See your distribution's documentation for - instructions to create a hashed password. - An empty string is not marshalled, because it is not a valid value. - type: string - name: - description: Name specifies the user name. - type: string - sshAuthorizedKeys: - description: |- - SSHAuthorizedKeys is a list of public SSH keys to write to the - machine. Use the corresponding private SSH keys to authenticate. See SSH - documentation for instructions to create a key pair. - items: - type: string - type: array - sudo: - description: |- - Sudo is a sudo user specification, formatted as described in the sudo - documentation. - An empty string is not marshalled, because it is not a valid value. - type: string - required: - - name - type: object - type: array - type: object - type: object - served: true - storage: true diff --git a/api/v1alpha1/crds/caren.nutanix.com_nutanixclusterconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_nutanixclusterconfigs.yaml index fa546edff..1d7b4c9aa 100644 --- a/api/v1alpha1/crds/caren.nutanix.com_nutanixclusterconfigs.yaml +++ b/api/v1alpha1/crds/caren.nutanix.com_nutanixclusterconfigs.yaml @@ -384,8 +384,10 @@ spec: extraAPIServerCertSANs: description: |- Subject Alternative Names for the API Server signing cert. - For Docker are injected automatically. - For Nutanix are injected automatically. + For the Nutanix provider, the following default SANs will always be added: + - localhost + - 127.0.0.1 + - 0.0.0.0 items: pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ type: string diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 2250faba0..936e25966 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -88,6 +88,11 @@ func (in *AWSClusterConfigSpec) DeepCopyInto(out *AWSClusterConfigSpec) { *out = new(AWSNodeConfigSpec) (*in).DeepCopyInto(*out) } + if in.ExtraAPIServerCertSANs != nil { + in, out := &in.ExtraAPIServerCertSANs, &out.ExtraAPIServerCertSANs + *out = make([]string, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AWSClusterConfigSpec. @@ -493,6 +498,11 @@ func (in *DockerClusterConfigSpec) DeepCopyInto(out *DockerClusterConfigSpec) { *out = new(DockerNodeConfigSpec) (*in).DeepCopyInto(*out) } + if in.ExtraAPIServerCertSANs != nil { + in, out := &in.ExtraAPIServerCertSANs, &out.ExtraAPIServerCertSANs + *out = make([]string, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DockerClusterConfigSpec. @@ -606,32 +616,6 @@ func (in *Etcd) DeepCopy() *Etcd { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *GenericClusterConfig) DeepCopyInto(out *GenericClusterConfig) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GenericClusterConfig. -func (in *GenericClusterConfig) DeepCopy() *GenericClusterConfig { - if in == nil { - return nil - } - out := new(GenericClusterConfig) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *GenericClusterConfig) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *GenericClusterConfigSpec) DeepCopyInto(out *GenericClusterConfigSpec) { *out = *in @@ -650,11 +634,6 @@ func (in *GenericClusterConfigSpec) DeepCopyInto(out *GenericClusterConfigSpec) *out = new(HTTPProxy) (*in).DeepCopyInto(*out) } - if in.ExtraAPIServerCertSANs != nil { - in, out := &in.ExtraAPIServerCertSANs, &out.ExtraAPIServerCertSANs - *out = make([]string, len(*in)) - copy(*out, *in) - } if in.ImageRegistries != nil { in, out := &in.ImageRegistries, &out.ImageRegistries *out = make([]ImageRegistry, len(*in)) @@ -821,6 +800,11 @@ func (in *NutanixClusterConfigSpec) DeepCopyInto(out *NutanixClusterConfigSpec) *out = new(NutanixNodeConfigSpec) (*in).DeepCopyInto(*out) } + if in.ExtraAPIServerCertSANs != nil { + in, out := &in.ExtraAPIServerCertSANs, &out.ExtraAPIServerCertSANs + *out = make([]string, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NutanixClusterConfigSpec. diff --git a/pkg/handlers/generic/clusterconfig/variables.go b/pkg/handlers/generic/clusterconfig/variables.go index f6cbce559..3803bc1c0 100644 --- a/pkg/handlers/generic/clusterconfig/variables.go +++ b/pkg/handlers/generic/clusterconfig/variables.go @@ -3,22 +3,6 @@ package clusterconfig -import ( - "context" - - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" - runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" - - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" - commonhandlers "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers" - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation" -) - -var ( - _ commonhandlers.Named = &clusterConfigVariableHandler{} - _ mutation.DiscoverVariables = &clusterConfigVariableHandler{} -) - const ( // MetaVariableName is the meta cluster config patch variable name. MetaVariableName = "clusterConfig" @@ -29,26 +13,3 @@ const ( // HandlerNameVariable is the name of the variable handler. HandlerNameVariable = "ClusterConfigVars" ) - -func NewVariable() *clusterConfigVariableHandler { - return &clusterConfigVariableHandler{} -} - -type clusterConfigVariableHandler struct{} - -func (h *clusterConfigVariableHandler) Name() string { - return HandlerNameVariable -} - -func (h *clusterConfigVariableHandler) DiscoverVariables( - ctx context.Context, - _ *runtimehooksv1.DiscoverVariablesRequest, - resp *runtimehooksv1.DiscoverVariablesResponse, -) { - resp.Variables = append(resp.Variables, clusterv1.ClusterClassVariable{ - Name: MetaVariableName, - Required: false, - Schema: v1alpha1.GenericClusterConfig{}.VariableSchema(), - }) - resp.SetStatus(runtimehooksv1.ResponseStatusSuccess) -} diff --git a/pkg/handlers/generic/clusterconfig/variables_test.go b/pkg/handlers/generic/clusterconfig/variables_test.go deleted file mode 100644 index e5c9d3bb9..000000000 --- a/pkg/handlers/generic/clusterconfig/variables_test.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2023 D2iQ, Inc. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package clusterconfig - -import ( - "testing" - - "k8s.io/utils/ptr" - - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest" -) - -func TestVariableValidation(t *testing.T) { - capitest.ValidateDiscoverVariables( - t, - MetaVariableName, - ptr.To(v1alpha1.GenericClusterConfig{}.VariableSchema()), - false, - NewVariable, - capitest.VariableTestDef{ - Name: "valid config", - Vals: v1alpha1.GenericClusterConfigSpec{ - Proxy: &v1alpha1.HTTPProxy{ - HTTP: "http://a.b.c.example.com", - HTTPS: "https://a.b.c.example.com", - AdditionalNo: []string{"d.e.f.example.com"}, - }, - ExtraAPIServerCertSANs: []string{"a.b.c.example.com"}, - }, - }, - ) -} diff --git a/pkg/handlers/generic/lifecycle/clusterautoscaler/variables_test.go b/pkg/handlers/generic/lifecycle/clusterautoscaler/variables_test.go index 3cd33c059..fa0050b48 100644 --- a/pkg/handlers/generic/lifecycle/clusterautoscaler/variables_test.go +++ b/pkg/handlers/generic/lifecycle/clusterautoscaler/variables_test.go @@ -10,16 +10,101 @@ import ( "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest" + awsclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/clusterconfig" + dockerclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/clusterconfig" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig" + nutanixclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/clusterconfig" ) -func TestVariableValidation(t *testing.T) { +func TestVariableValidation_AWS(t *testing.T) { capitest.ValidateDiscoverVariables( t, clusterconfig.MetaVariableName, - ptr.To(v1alpha1.GenericClusterConfig{}.VariableSchema()), - false, - clusterconfig.NewVariable, + ptr.To(v1alpha1.AWSClusterConfig{}.VariableSchema()), + true, + awsclusterconfig.NewVariable, + capitest.VariableTestDef{ + Name: "ClusterResourceSet strategy", + Vals: v1alpha1.GenericClusterConfigSpec{ + Addons: &v1alpha1.Addons{ + ClusterAutoscaler: &v1alpha1.ClusterAutoscaler{ + Strategy: v1alpha1.AddonStrategyClusterResourceSet, + }, + }, + }, + }, + capitest.VariableTestDef{ + Name: "HelmAddon strategy", + Vals: v1alpha1.GenericClusterConfigSpec{ + Addons: &v1alpha1.Addons{ + ClusterAutoscaler: &v1alpha1.ClusterAutoscaler{ + Strategy: v1alpha1.AddonStrategyHelmAddon, + }, + }, + }, + }, + capitest.VariableTestDef{ + Name: "invalid strategy", + Vals: v1alpha1.GenericClusterConfigSpec{ + Addons: &v1alpha1.Addons{ + ClusterAutoscaler: &v1alpha1.ClusterAutoscaler{ + Strategy: "invalid-strategy", + }, + }, + }, + ExpectError: true, + }, + ) +} + +func TestVariableValidation_Nutanix(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.NutanixClusterConfig{}.VariableSchema()), + true, + nutanixclusterconfig.NewVariable, + capitest.VariableTestDef{ + Name: "ClusterResourceSet strategy", + Vals: v1alpha1.GenericClusterConfigSpec{ + Addons: &v1alpha1.Addons{ + ClusterAutoscaler: &v1alpha1.ClusterAutoscaler{ + Strategy: v1alpha1.AddonStrategyClusterResourceSet, + }, + }, + }, + }, + capitest.VariableTestDef{ + Name: "HelmAddon strategy", + Vals: v1alpha1.GenericClusterConfigSpec{ + Addons: &v1alpha1.Addons{ + ClusterAutoscaler: &v1alpha1.ClusterAutoscaler{ + Strategy: v1alpha1.AddonStrategyHelmAddon, + }, + }, + }, + }, + capitest.VariableTestDef{ + Name: "invalid strategy", + Vals: v1alpha1.GenericClusterConfigSpec{ + Addons: &v1alpha1.Addons{ + ClusterAutoscaler: &v1alpha1.ClusterAutoscaler{ + Strategy: "invalid-strategy", + }, + }, + }, + ExpectError: true, + }, + ) +} + +func TestVariableValidation_Docker(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.DockerClusterConfig{}.VariableSchema()), + true, + dockerclusterconfig.NewVariable, capitest.VariableTestDef{ Name: "ClusterResourceSet strategy", Vals: v1alpha1.GenericClusterConfigSpec{ diff --git a/pkg/handlers/generic/lifecycle/cni/variables_test.go b/pkg/handlers/generic/lifecycle/cni/variables_test.go index 9c6e515e7..d68314cea 100644 --- a/pkg/handlers/generic/lifecycle/cni/variables_test.go +++ b/pkg/handlers/generic/lifecycle/cni/variables_test.go @@ -10,61 +10,85 @@ import ( "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest" + awsclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/clusterconfig" + dockerclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/clusterconfig" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig" + nutanixclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/clusterconfig" ) -func TestVariableValidation(t *testing.T) { - capitest.ValidateDiscoverVariables( - t, - clusterconfig.MetaVariableName, - ptr.To(v1alpha1.GenericClusterConfig{}.VariableSchema()), - false, - clusterconfig.NewVariable, - capitest.VariableTestDef{ - Name: "set with valid provider using ClusterResourceSet strategy", - Vals: v1alpha1.GenericClusterConfigSpec{ - Addons: &v1alpha1.Addons{ - CNI: &v1alpha1.CNI{ - Provider: v1alpha1.CNIProviderCalico, - Strategy: v1alpha1.AddonStrategyClusterResourceSet, - }, - }, +var testDefs = []capitest.VariableTestDef{{ + Name: "set with valid provider using ClusterResourceSet strategy", + Vals: v1alpha1.GenericClusterConfigSpec{ + Addons: &v1alpha1.Addons{ + CNI: &v1alpha1.CNI{ + Provider: v1alpha1.CNIProviderCalico, + Strategy: v1alpha1.AddonStrategyClusterResourceSet, }, }, - capitest.VariableTestDef{ - Name: "set with valid provider using HelmAddon strategy", - Vals: v1alpha1.GenericClusterConfigSpec{ - Addons: &v1alpha1.Addons{ - CNI: &v1alpha1.CNI{ - Provider: v1alpha1.CNIProviderCalico, - Strategy: v1alpha1.AddonStrategyHelmAddon, - }, - }, + }, +}, { + Name: "set with valid provider using HelmAddon strategy", + Vals: v1alpha1.GenericClusterConfigSpec{ + Addons: &v1alpha1.Addons{ + CNI: &v1alpha1.CNI{ + Provider: v1alpha1.CNIProviderCalico, + Strategy: v1alpha1.AddonStrategyHelmAddon, }, }, - capitest.VariableTestDef{ - Name: "set with invalid provider", - Vals: v1alpha1.GenericClusterConfigSpec{ - Addons: &v1alpha1.Addons{ - CNI: &v1alpha1.CNI{ - Provider: "invalid-provider", - Strategy: v1alpha1.AddonStrategyClusterResourceSet, - }, - }, + }, +}, { + Name: "set with invalid provider", + Vals: v1alpha1.GenericClusterConfigSpec{ + Addons: &v1alpha1.Addons{ + CNI: &v1alpha1.CNI{ + Provider: "invalid-provider", + Strategy: v1alpha1.AddonStrategyClusterResourceSet, }, - ExpectError: true, }, - capitest.VariableTestDef{ - Name: "set with invalid strategy", - Vals: v1alpha1.GenericClusterConfigSpec{ - Addons: &v1alpha1.Addons{ - CNI: &v1alpha1.CNI{ - Provider: v1alpha1.CNIProviderCalico, - Strategy: "invalid-strategy", - }, - }, + }, + ExpectError: true, +}, { + Name: "set with invalid strategy", + Vals: v1alpha1.GenericClusterConfigSpec{ + Addons: &v1alpha1.Addons{ + CNI: &v1alpha1.CNI{ + Provider: v1alpha1.CNIProviderCalico, + Strategy: "invalid-strategy", }, - ExpectError: true, }, + }, + ExpectError: true, +}} + +func TestVariableValidation_AWS(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.AWSClusterConfig{}.VariableSchema()), + true, + awsclusterconfig.NewVariable, + testDefs..., + ) +} + +func TestVariableValidation_Docker(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.DockerClusterConfig{}.VariableSchema()), + true, + dockerclusterconfig.NewVariable, + testDefs..., + ) +} + +func TestVariableValidation_Nutanix(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.NutanixClusterConfig{}.VariableSchema()), + true, + nutanixclusterconfig.NewVariable, + testDefs..., ) } diff --git a/pkg/handlers/generic/lifecycle/nfd/variables_test.go b/pkg/handlers/generic/lifecycle/nfd/variables_test.go index b615e4c92..984645ab7 100644 --- a/pkg/handlers/generic/lifecycle/nfd/variables_test.go +++ b/pkg/handlers/generic/lifecycle/nfd/variables_test.go @@ -10,46 +10,71 @@ import ( "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest" + awsclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/clusterconfig" + dockerclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/clusterconfig" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig" + nutanixclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/clusterconfig" ) -func TestVariableValidation(t *testing.T) { - capitest.ValidateDiscoverVariables( - t, - clusterconfig.MetaVariableName, - ptr.To(v1alpha1.GenericClusterConfig{}.VariableSchema()), - false, - clusterconfig.NewVariable, - capitest.VariableTestDef{ - Name: "ClusterResourceSet strategy", - Vals: v1alpha1.GenericClusterConfigSpec{ - Addons: &v1alpha1.Addons{ - NFD: &v1alpha1.NFD{ - Strategy: v1alpha1.AddonStrategyClusterResourceSet, - }, - }, +var testDefs = []capitest.VariableTestDef{{ + Name: "ClusterResourceSet strategy", + Vals: v1alpha1.GenericClusterConfigSpec{ + Addons: &v1alpha1.Addons{ + NFD: &v1alpha1.NFD{ + Strategy: v1alpha1.AddonStrategyClusterResourceSet, }, }, - capitest.VariableTestDef{ - Name: "HelmAddon strategy", - Vals: v1alpha1.GenericClusterConfigSpec{ - Addons: &v1alpha1.Addons{ - NFD: &v1alpha1.NFD{ - Strategy: v1alpha1.AddonStrategyHelmAddon, - }, - }, + }, +}, { + Name: "HelmAddon strategy", + Vals: v1alpha1.GenericClusterConfigSpec{ + Addons: &v1alpha1.Addons{ + NFD: &v1alpha1.NFD{ + Strategy: v1alpha1.AddonStrategyHelmAddon, }, }, - capitest.VariableTestDef{ - Name: "invalid strategy", - Vals: v1alpha1.GenericClusterConfigSpec{ - Addons: &v1alpha1.Addons{ - NFD: &v1alpha1.NFD{ - Strategy: "invalid-strategy", - }, - }, + }, +}, { + Name: "invalid strategy", + Vals: v1alpha1.GenericClusterConfigSpec{ + Addons: &v1alpha1.Addons{ + NFD: &v1alpha1.NFD{ + Strategy: "invalid-strategy", }, - ExpectError: true, }, + }, + ExpectError: true, +}} + +func TestVariableValidation_AWS(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.AWSClusterConfig{}.VariableSchema()), + true, + awsclusterconfig.NewVariable, + testDefs..., + ) +} + +func TestVariableValidation_Docker(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.DockerClusterConfig{}.VariableSchema()), + true, + dockerclusterconfig.NewVariable, + testDefs..., + ) +} + +func TestVariableValidation_Nutanix(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.NutanixClusterConfig{}.VariableSchema()), + true, + nutanixclusterconfig.NewVariable, + testDefs..., ) } diff --git a/pkg/handlers/generic/mutation/etcd/variables_test.go b/pkg/handlers/generic/mutation/etcd/variables_test.go index 143451ac4..6ab2f75e8 100644 --- a/pkg/handlers/generic/mutation/etcd/variables_test.go +++ b/pkg/handlers/generic/mutation/etcd/variables_test.go @@ -10,54 +10,78 @@ import ( "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest" + awsclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/clusterconfig" + dockerclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/clusterconfig" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig" + nutanixclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/clusterconfig" ) -func TestVariableValidation(t *testing.T) { - capitest.ValidateDiscoverVariables( - t, - clusterconfig.MetaVariableName, - ptr.To(v1alpha1.GenericClusterConfig{}.VariableSchema()), - false, - clusterconfig.NewVariable, - capitest.VariableTestDef{ - Name: "unset", - Vals: v1alpha1.GenericClusterConfigSpec{ - Etcd: &v1alpha1.Etcd{}, +var testDefs = []capitest.VariableTestDef{{ + Name: "unset", + Vals: v1alpha1.GenericClusterConfigSpec{ + Etcd: &v1alpha1.Etcd{}, + }, +}, { + Name: "set with valid image values", + Vals: v1alpha1.GenericClusterConfigSpec{ + Etcd: &v1alpha1.Etcd{ + Image: &v1alpha1.Image{ + Repository: "my-registry.io/my-org/my-repo", + Tag: "v3.5.99_custom.0", }, }, - capitest.VariableTestDef{ - Name: "set with valid image values", - Vals: v1alpha1.GenericClusterConfigSpec{ - Etcd: &v1alpha1.Etcd{ - Image: &v1alpha1.Image{ - Repository: "my-registry.io/my-org/my-repo", - Tag: "v3.5.99_custom.0", - }, - }, + }, +}, { + Name: "set with invalid image repository", + Vals: v1alpha1.GenericClusterConfigSpec{ + Etcd: &v1alpha1.Etcd{ + Image: &v1alpha1.Image{ + Repository: "https://this.should.not.have.a.scheme", }, }, - capitest.VariableTestDef{ - Name: "set with invalid image repository", - Vals: v1alpha1.GenericClusterConfigSpec{ - Etcd: &v1alpha1.Etcd{ - Image: &v1alpha1.Image{ - Repository: "https://this.should.not.have.a.scheme", - }, - }, + }, + ExpectError: true, +}, { + Name: "set with invalid image tag", + Vals: v1alpha1.GenericClusterConfigSpec{ + Etcd: &v1alpha1.Etcd{ + Image: &v1alpha1.Image{ + Tag: "this:is:not:a:valid:tag", }, - ExpectError: true, - }, - capitest.VariableTestDef{ - Name: "set with invalid image tag", - Vals: v1alpha1.GenericClusterConfigSpec{ - Etcd: &v1alpha1.Etcd{ - Image: &v1alpha1.Image{ - Tag: "this:is:not:a:valid:tag", - }, - }, - }, - ExpectError: true, }, + }, + ExpectError: true, +}} + +func TestVariableValidation_AWS(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.AWSClusterConfig{}.VariableSchema()), + true, + awsclusterconfig.NewVariable, + testDefs..., + ) +} + +func TestVariableValidation_Docker(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.DockerClusterConfig{}.VariableSchema()), + true, + dockerclusterconfig.NewVariable, + testDefs..., + ) +} + +func TestVariableValidation_Nutanix(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.NutanixClusterConfig{}.VariableSchema()), + true, + nutanixclusterconfig.NewVariable, + testDefs..., ) } diff --git a/pkg/handlers/generic/mutation/extraapiservercertsans/inject_test.go b/pkg/handlers/generic/mutation/extraapiservercertsans/inject_test.go index b7ba69991..a9d68407b 100644 --- a/pkg/handlers/generic/mutation/extraapiservercertsans/inject_test.go +++ b/pkg/handlers/generic/mutation/extraapiservercertsans/inject_test.go @@ -52,12 +52,10 @@ var _ = Describe("Generate Extra API server certificate patches", func() { capitest.VariableWithValue( clusterconfig.MetaVariableName, v1alpha1.AWSClusterConfigSpec{ - GenericClusterConfigSpec: v1alpha1.GenericClusterConfigSpec{ - ExtraAPIServerCertSANs: []string{ - "a.b.c.example.com", - "a.b.c.example.com", - "d.e.f.example.com", - }, + ExtraAPIServerCertSANs: []string{ + "a.b.c.example.com", + "a.b.c.example.com", + "d.e.f.example.com", }, AWS: &v1alpha1.AWSSpec{}, }, @@ -92,7 +90,7 @@ var _ = Describe("Generate Extra API server certificate patches", func() { Vars: []runtimehooksv1.Variable{ capitest.VariableWithValue( clusterconfig.MetaVariableName, - v1alpha1.GenericClusterConfigSpec{ + v1alpha1.DockerClusterConfigSpec{ ExtraAPIServerCertSANs: []string{ "a.b.c.example.com", }, @@ -134,7 +132,7 @@ var _ = Describe("Generate Extra API server certificate patches", func() { Vars: []runtimehooksv1.Variable{ capitest.VariableWithValue( clusterconfig.MetaVariableName, - v1alpha1.GenericClusterConfigSpec{ + v1alpha1.NutanixClusterConfigSpec{ ExtraAPIServerCertSANs: []string{ "a.b.c.example.com", }, diff --git a/pkg/handlers/generic/mutation/extraapiservercertsans/variables_test.go b/pkg/handlers/generic/mutation/extraapiservercertsans/variables_test.go index 1ac50a83c..a4701fedd 100644 --- a/pkg/handlers/generic/mutation/extraapiservercertsans/variables_test.go +++ b/pkg/handlers/generic/mutation/extraapiservercertsans/variables_test.go @@ -10,38 +10,101 @@ import ( "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest" + awsclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/clusterconfig" + dockerclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/clusterconfig" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig" + nutanixclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/clusterconfig" ) -func TestVariableValidation(t *testing.T) { +func TestVariableValidation_AWS(t *testing.T) { capitest.ValidateDiscoverVariables( t, clusterconfig.MetaVariableName, - ptr.To(v1alpha1.GenericClusterConfig{}.VariableSchema()), - false, - clusterconfig.NewVariable, - capitest.VariableTestDef{ + ptr.To(v1alpha1.AWSClusterConfig{}.VariableSchema()), + true, + awsclusterconfig.NewVariable, + []capitest.VariableTestDef{{ Name: "single valid SAN", - Vals: v1alpha1.GenericClusterConfigSpec{ + Vals: v1alpha1.AWSClusterConfigSpec{ ExtraAPIServerCertSANs: []string{"a.b.c.example.com"}, }, - }, - capitest.VariableTestDef{ + }, { Name: "single invalid SAN", - Vals: v1alpha1.GenericClusterConfigSpec{ + Vals: v1alpha1.AWSClusterConfigSpec{ ExtraAPIServerCertSANs: []string{"invalid:san"}, }, ExpectError: true, - }, - capitest.VariableTestDef{ + }, { Name: "duplicate valid SANs", - Vals: v1alpha1.GenericClusterConfigSpec{ + Vals: v1alpha1.AWSClusterConfigSpec{ ExtraAPIServerCertSANs: []string{ "a.b.c.example.com", "a.b.c.example.com", }, }, ExpectError: true, - }, + }}..., + ) +} + +func TestVariableValidation_Docker(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.DockerClusterConfig{}.VariableSchema()), + true, + dockerclusterconfig.NewVariable, + []capitest.VariableTestDef{{ + Name: "single valid SAN", + Vals: v1alpha1.DockerClusterConfigSpec{ + ExtraAPIServerCertSANs: []string{"a.b.c.example.com"}, + }, + }, { + Name: "single invalid SAN", + Vals: v1alpha1.DockerClusterConfigSpec{ + ExtraAPIServerCertSANs: []string{"invalid:san"}, + }, + ExpectError: true, + }, { + Name: "duplicate valid SANs", + Vals: v1alpha1.DockerClusterConfigSpec{ + ExtraAPIServerCertSANs: []string{ + "a.b.c.example.com", + "a.b.c.example.com", + }, + }, + ExpectError: true, + }}..., + ) +} + +func TestVariableValidation_Nutanix(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.NutanixClusterConfig{}.VariableSchema()), + true, + nutanixclusterconfig.NewVariable, + []capitest.VariableTestDef{{ + Name: "single valid SAN", + Vals: v1alpha1.NutanixClusterConfigSpec{ + ExtraAPIServerCertSANs: []string{"a.b.c.example.com"}, + }, + }, { + Name: "single invalid SAN", + Vals: v1alpha1.NutanixClusterConfigSpec{ + ExtraAPIServerCertSANs: []string{"invalid:san"}, + }, + ExpectError: true, + }, { + Name: "duplicate valid SANs", + Vals: v1alpha1.NutanixClusterConfigSpec{ + ExtraAPIServerCertSANs: []string{ + "a.b.c.example.com", + "a.b.c.example.com", + }, + }, + ExpectError: true, + }}..., ) } diff --git a/pkg/handlers/generic/mutation/httpproxy/variables_test.go b/pkg/handlers/generic/mutation/httpproxy/variables_test.go index ec597ee46..46bef2cc0 100644 --- a/pkg/handlers/generic/mutation/httpproxy/variables_test.go +++ b/pkg/handlers/generic/mutation/httpproxy/variables_test.go @@ -10,26 +10,52 @@ import ( "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest" + awsclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/clusterconfig" + dockerclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/clusterconfig" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig" + nutanixclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/clusterconfig" ) -func TestVariableValidation(t *testing.T) { +var testDefs = []capitest.VariableTestDef{{ + Name: "valid proxy config", + Vals: v1alpha1.GenericClusterConfigSpec{ + Proxy: &v1alpha1.HTTPProxy{ + HTTP: "http://a.b.c.example.com", + HTTPS: "https://a.b.c.example.com", + AdditionalNo: []string{"d.e.f.example.com"}, + }, + }, +}} + +func TestVariableValidation_AWS(t *testing.T) { capitest.ValidateDiscoverVariables( t, clusterconfig.MetaVariableName, - ptr.To(v1alpha1.GenericClusterConfig{}.VariableSchema()), - false, - clusterconfig.NewVariable, - // HTTPProxy - capitest.VariableTestDef{ - Name: "valid proxy config", - Vals: v1alpha1.GenericClusterConfigSpec{ - Proxy: &v1alpha1.HTTPProxy{ - HTTP: "http://a.b.c.example.com", - HTTPS: "https://a.b.c.example.com", - AdditionalNo: []string{"d.e.f.example.com"}, - }, - }, - }, + ptr.To(v1alpha1.AWSClusterConfig{}.VariableSchema()), + true, + awsclusterconfig.NewVariable, + testDefs..., + ) +} + +func TestVariableValidation_Docker(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.DockerClusterConfig{}.VariableSchema()), + true, + dockerclusterconfig.NewVariable, + testDefs..., + ) +} + +func TestVariableValidation_Nutanix(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.NutanixClusterConfig{}.VariableSchema()), + true, + nutanixclusterconfig.NewVariable, + testDefs..., ) } diff --git a/pkg/handlers/generic/mutation/imageregistries/credentials/variables_test.go b/pkg/handlers/generic/mutation/imageregistries/credentials/variables_test.go index 676062466..0b520e661 100644 --- a/pkg/handlers/generic/mutation/imageregistries/credentials/variables_test.go +++ b/pkg/handlers/generic/mutation/imageregistries/credentials/variables_test.go @@ -11,75 +11,100 @@ import ( "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest" + awsclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/clusterconfig" + dockerclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/clusterconfig" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig" + nutanixclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/clusterconfig" ) -func TestVariableValidation(t *testing.T) { - capitest.ValidateDiscoverVariables( - t, - clusterconfig.MetaVariableName, - ptr.To(v1alpha1.GenericClusterConfig{}.VariableSchema()), - false, - clusterconfig.NewVariable, - capitest.VariableTestDef{ - Name: "without a credentials secret", - Vals: v1alpha1.GenericClusterConfigSpec{ - ImageRegistries: []v1alpha1.ImageRegistry{ - { - URL: "http://a.b.c.example.com", - }, +var testDefs = []capitest.VariableTestDef{ + { + Name: "without a credentials secret", + Vals: v1alpha1.GenericClusterConfigSpec{ + ImageRegistries: []v1alpha1.ImageRegistry{ + { + URL: "http://a.b.c.example.com", }, }, }, - capitest.VariableTestDef{ - Name: "with a credentials secret", - Vals: v1alpha1.GenericClusterConfigSpec{ - ImageRegistries: []v1alpha1.ImageRegistry{ - { - URL: "https://a.b.c.example.com/a/b/c", - Credentials: &v1alpha1.RegistryCredentials{ - SecretRef: &corev1.LocalObjectReference{ - Name: "a.b.c.example.com-creds", - }, + }, { + Name: "with a credentials secret", + Vals: v1alpha1.GenericClusterConfigSpec{ + ImageRegistries: []v1alpha1.ImageRegistry{ + { + URL: "https://a.b.c.example.com/a/b/c", + Credentials: &v1alpha1.RegistryCredentials{ + SecretRef: &corev1.LocalObjectReference{ + Name: "a.b.c.example.com-creds", }, }, }, }, }, - capitest.VariableTestDef{ - Name: "support for multiple image registries", - Vals: v1alpha1.GenericClusterConfigSpec{ - ImageRegistries: []v1alpha1.ImageRegistry{ - { - URL: "http://first-image-registry.example.com", - }, - { - URL: "http://second-image-registry.example.com", - }, + }, { + Name: "support for multiple image registries", + Vals: v1alpha1.GenericClusterConfigSpec{ + ImageRegistries: []v1alpha1.ImageRegistry{ + { + URL: "http://first-image-registry.example.com", + }, + { + URL: "http://second-image-registry.example.com", }, }, }, - capitest.VariableTestDef{ - Name: "invalid registry URL", - Vals: v1alpha1.GenericClusterConfigSpec{ - ImageRegistries: []v1alpha1.ImageRegistry{ - { - URL: "unsupportedformat://a.b.c.example.com", - }, + }, { + Name: "invalid registry URL", + Vals: v1alpha1.GenericClusterConfigSpec{ + ImageRegistries: []v1alpha1.ImageRegistry{ + { + URL: "unsupportedformat://a.b.c.example.com", }, }, - ExpectError: true, }, - capitest.VariableTestDef{ - Name: "registry URL without format", - Vals: v1alpha1.GenericClusterConfigSpec{ - ImageRegistries: []v1alpha1.ImageRegistry{ - { - URL: "a.b.c.example.com/a/b/c", - }, + ExpectError: true, + }, { + Name: "registry URL without format", + Vals: v1alpha1.GenericClusterConfigSpec{ + ImageRegistries: []v1alpha1.ImageRegistry{ + { + URL: "a.b.c.example.com/a/b/c", }, }, - ExpectError: true, }, + ExpectError: true, + }, +} + +func TestVariableValidation_AWS(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.AWSClusterConfig{}.VariableSchema()), + true, + awsclusterconfig.NewVariable, + testDefs..., + ) +} + +func TestVariableValidation_Docker(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.DockerClusterConfig{}.VariableSchema()), + true, + dockerclusterconfig.NewVariable, + testDefs..., + ) +} + +func TestVariableValidation_Nutanix(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.NutanixClusterConfig{}.VariableSchema()), + true, + nutanixclusterconfig.NewVariable, + testDefs..., ) } diff --git a/pkg/handlers/generic/mutation/kubernetesimagerepository/variables_test.go b/pkg/handlers/generic/mutation/kubernetesimagerepository/variables_test.go index 83d39368d..690d32a87 100644 --- a/pkg/handlers/generic/mutation/kubernetesimagerepository/variables_test.go +++ b/pkg/handlers/generic/mutation/kubernetesimagerepository/variables_test.go @@ -10,24 +10,50 @@ import ( "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest" + awsclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/clusterconfig" + dockerclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/clusterconfig" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig" + nutanixclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/clusterconfig" ) -func TestVariableValidation(t *testing.T) { +var testDefs = []capitest.VariableTestDef{{ + Name: "set", + Vals: v1alpha1.GenericClusterConfigSpec{ + KubernetesImageRepository: ptr.To( + "my-registry.io/my-org/my-repo", + ), + }, +}} + +func TestVariableValidation_AWS(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.AWSClusterConfig{}.VariableSchema()), + true, + awsclusterconfig.NewVariable, + testDefs..., + ) +} + +func TestVariableValidation_Docker(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.DockerClusterConfig{}.VariableSchema()), + true, + dockerclusterconfig.NewVariable, + testDefs..., + ) +} + +func TestVariableValidation_Nutanix(t *testing.T) { capitest.ValidateDiscoverVariables( t, clusterconfig.MetaVariableName, - ptr.To(v1alpha1.GenericClusterConfig{}.VariableSchema()), - false, - clusterconfig.NewVariable, - // KubernetesImageRepository - capitest.VariableTestDef{ - Name: "set", - Vals: v1alpha1.GenericClusterConfigSpec{ - KubernetesImageRepository: ptr.To( - "my-registry.io/my-org/my-repo", - ), - }, - }, + ptr.To(v1alpha1.NutanixClusterConfig{}.VariableSchema()), + true, + nutanixclusterconfig.NewVariable, + testDefs..., ) } diff --git a/pkg/handlers/generic/mutation/mirrors/variables_test.go b/pkg/handlers/generic/mutation/mirrors/variables_test.go index 846ad3fa1..dbd3e14f6 100644 --- a/pkg/handlers/generic/mutation/mirrors/variables_test.go +++ b/pkg/handlers/generic/mutation/mirrors/variables_test.go @@ -11,54 +11,78 @@ import ( "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest" + awsclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/clusterconfig" + dockerclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/clusterconfig" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig" + nutanixclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/clusterconfig" ) -func TestVariableValidation(t *testing.T) { - capitest.ValidateDiscoverVariables( - t, - clusterconfig.MetaVariableName, - ptr.To(v1alpha1.GenericClusterConfig{}.VariableSchema()), - false, - clusterconfig.NewVariable, - capitest.VariableTestDef{ - Name: "without a credentials secret", - Vals: v1alpha1.GenericClusterConfigSpec{ - GlobalImageRegistryMirror: &v1alpha1.GlobalImageRegistryMirror{ - URL: "http://a.b.c.example.com", - }, - }, +var testDefs = []capitest.VariableTestDef{{ + Name: "without a credentials secret", + Vals: v1alpha1.GenericClusterConfigSpec{ + GlobalImageRegistryMirror: &v1alpha1.GlobalImageRegistryMirror{ + URL: "http://a.b.c.example.com", }, - capitest.VariableTestDef{ - Name: "with a credentials CA secret", - Vals: v1alpha1.GenericClusterConfigSpec{ - GlobalImageRegistryMirror: &v1alpha1.GlobalImageRegistryMirror{ - URL: "http://a.b.c.example.com", - Credentials: &v1alpha1.RegistryCredentials{ - SecretRef: &corev1.LocalObjectReference{ - Name: "a.b.c.example.com-ca-cert-creds", - }, - }, + }, +}, { + Name: "with a credentials CA secret", + Vals: v1alpha1.GenericClusterConfigSpec{ + GlobalImageRegistryMirror: &v1alpha1.GlobalImageRegistryMirror{ + URL: "http://a.b.c.example.com", + Credentials: &v1alpha1.RegistryCredentials{ + SecretRef: &corev1.LocalObjectReference{ + Name: "a.b.c.example.com-ca-cert-creds", }, }, }, - capitest.VariableTestDef{ - Name: "invalid mirror registry URL", - Vals: v1alpha1.GenericClusterConfigSpec{ - GlobalImageRegistryMirror: &v1alpha1.GlobalImageRegistryMirror{ - URL: "unsupportedformat://a.b.c.example.com", - }, - }, - ExpectError: true, + }, +}, { + Name: "invalid mirror registry URL", + Vals: v1alpha1.GenericClusterConfigSpec{ + GlobalImageRegistryMirror: &v1alpha1.GlobalImageRegistryMirror{ + URL: "unsupportedformat://a.b.c.example.com", }, - capitest.VariableTestDef{ - Name: "mirror URL without format", - Vals: v1alpha1.GenericClusterConfigSpec{ - GlobalImageRegistryMirror: &v1alpha1.GlobalImageRegistryMirror{ - URL: "a.b.c.example.com/a/b/c", - }, - }, - ExpectError: true, + }, + ExpectError: true, +}, { + Name: "mirror URL without format", + Vals: v1alpha1.GenericClusterConfigSpec{ + GlobalImageRegistryMirror: &v1alpha1.GlobalImageRegistryMirror{ + URL: "a.b.c.example.com/a/b/c", }, + }, + ExpectError: true, +}} + +func TestVariableValidation_AWS(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.AWSClusterConfig{}.VariableSchema()), + true, + awsclusterconfig.NewVariable, + testDefs..., + ) +} + +func TestVariableValidation_Docker(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.DockerClusterConfig{}.VariableSchema()), + true, + dockerclusterconfig.NewVariable, + testDefs..., + ) +} + +func TestVariableValidation_Nutanix(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.NutanixClusterConfig{}.VariableSchema()), + true, + nutanixclusterconfig.NewVariable, + testDefs..., ) } diff --git a/pkg/handlers/generic/mutation/users/variables_test.go b/pkg/handlers/generic/mutation/users/variables_test.go index a89d527a7..83a6b9bda 100644 --- a/pkg/handlers/generic/mutation/users/variables_test.go +++ b/pkg/handlers/generic/mutation/users/variables_test.go @@ -10,34 +10,61 @@ import ( "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest" + awsclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/aws/clusterconfig" + dockerclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/clusterconfig" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig" + nutanixclusterconfig "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/pkg/handlers/nutanix/clusterconfig" ) -func TestVariableValidation(t *testing.T) { - capitest.ValidateDiscoverVariables( - t, - clusterconfig.MetaVariableName, - ptr.To(v1alpha1.GenericClusterConfig{}.VariableSchema()), - false, - clusterconfig.NewVariable, - capitest.VariableTestDef{ - Name: "valid users", - Vals: v1alpha1.GenericClusterConfigSpec{ - Users: []v1alpha1.User{ - { - Name: "complete", - HashedPassword: "password", - SSHAuthorizedKeys: []string{ - "key1", - "key2", - }, - Sudo: "ALL=(ALL) NOPASSWD:ALL", - }, - { - Name: "onlyname", - }, +var testDefs = []capitest.VariableTestDef{{ + Name: "valid users", + Vals: v1alpha1.GenericClusterConfigSpec{ + Users: []v1alpha1.User{ + { + Name: "complete", + HashedPassword: "password", + SSHAuthorizedKeys: []string{ + "key1", + "key2", }, + Sudo: "ALL=(ALL) NOPASSWD:ALL", + }, + { + Name: "onlyname", }, }, + }, +}} + +func TestVariableValidation_AWS(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.AWSClusterConfig{}.VariableSchema()), + true, + awsclusterconfig.NewVariable, + testDefs..., + ) +} + +func TestVariableValidation_Docker(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.DockerClusterConfig{}.VariableSchema()), + true, + dockerclusterconfig.NewVariable, + testDefs..., + ) +} + +func TestVariableValidation_Nutanix(t *testing.T) { + capitest.ValidateDiscoverVariables( + t, + clusterconfig.MetaVariableName, + ptr.To(v1alpha1.NutanixClusterConfig{}.VariableSchema()), + true, + nutanixclusterconfig.NewVariable, + testDefs..., ) } From 42030739f72f3d8ce14ea412c8528d20fe990359 Mon Sep 17 00:00:00 2001 From: Jimmi Dyson Date: Thu, 18 Apr 2024 21:45:47 +0100 Subject: [PATCH 4/6] refactor: Separate defaults for worker and CP AWS nodes --- api/go.mod | 12 +- api/go.sum | 31 +-- api/v1alpha1/aws_node_types.go | 166 ++++------------ api/v1alpha1/clusterconfig_types.go | 2 +- .../caren.nutanix.com_awsclusterconfigs.yaml | 21 +- ...ren.nutanix.com_awsworkernodeconfigs.yaml} | 33 ++-- api/v1alpha1/docker_clusterconfig_types.go | 14 -- api/v1alpha1/nodeconfig_types.go | 36 ++-- api/v1alpha1/zz_generated.deepcopy.go | 183 +++++++++++------- .../aws/mutation/ami/variables_test.go | 18 +- .../inject_control_plane.go | 4 +- .../iaminstanceprofile/inject_worker.go | 4 +- .../iaminstanceprofile/variables_test.go | 18 +- .../instancetype/inject_control_plane.go | 4 +- .../mutation/instancetype/inject_worker.go | 4 +- .../mutation/instancetype/variables_test.go | 6 +- .../aws/mutation/securitygroups/inject.go | 3 +- .../inject_control_plane_test.go | 7 +- .../securitygroups/inject_worker_test.go | 7 +- .../mutation/securitygroups/variables_test.go | 18 +- pkg/handlers/aws/workerconfig/variables.go | 2 +- .../aws/workerconfig/variables_test.go | 16 +- 22 files changed, 284 insertions(+), 325 deletions(-) rename api/v1alpha1/crds/{caren.nutanix.com_awsnodeconfigs.yaml => caren.nutanix.com_awsworkernodeconfigs.yaml} (69%) diff --git a/api/go.mod b/api/go.mod index befb33a07..0b8eeadb0 100644 --- a/api/go.mod +++ b/api/go.mod @@ -16,7 +16,6 @@ require ( k8s.io/api v0.29.3 k8s.io/apiextensions-apiserver v0.29.3 k8s.io/apimachinery v0.29.3 - k8s.io/utils v0.0.0-20231127182322-b307cd553661 sigs.k8s.io/cluster-api v1.7.0 sigs.k8s.io/controller-runtime v0.17.3 ) @@ -26,7 +25,7 @@ require ( github.com/blang/semver/v4 v4.0.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect - github.com/emicklei/go-restful/v3 v3.11.0 // indirect + github.com/emicklei/go-restful/v3 v3.12.0 // indirect github.com/evanphx/json-patch/v5 v5.9.0 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-logr/logr v1.4.1 // indirect @@ -39,7 +38,7 @@ require ( github.com/google/gnostic-models v0.6.8 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/google/gofuzz v1.2.0 // indirect - github.com/google/uuid v1.3.1 // indirect + github.com/google/uuid v1.4.0 // indirect github.com/imdario/mergo v0.3.13 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect @@ -57,13 +56,13 @@ require ( github.com/valyala/fastjson v1.6.4 // indirect golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect golang.org/x/net v0.24.0 // indirect - golang.org/x/oauth2 v0.14.0 // indirect + golang.org/x/oauth2 v0.18.0 // indirect golang.org/x/sys v0.19.0 // indirect golang.org/x/term v0.19.0 // indirect golang.org/x/text v0.14.0 // indirect - golang.org/x/time v0.3.0 // indirect + golang.org/x/time v0.5.0 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect - google.golang.org/appengine v1.6.7 // indirect + google.golang.org/appengine v1.6.8 // indirect google.golang.org/protobuf v1.33.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect @@ -72,6 +71,7 @@ require ( k8s.io/component-base v0.29.3 // indirect k8s.io/klog/v2 v2.120.1 // indirect k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect + k8s.io/utils v0.0.0-20231127182322-b307cd553661 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect sigs.k8s.io/yaml v1.4.0 // indirect diff --git a/api/go.sum b/api/go.sum index c42d5ad3f..88c2af63f 100644 --- a/api/go.sum +++ b/api/go.sum @@ -98,8 +98,8 @@ github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3 github.com/elazarl/goproxy v0.0.0-20180725130230-947c36da3153/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= github.com/emicklei/go-restful v2.9.5+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= -github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g= -github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= +github.com/emicklei/go-restful/v3 v3.12.0 h1:y2DdzBAURM29NFF94q6RaY4vjIH1rtwDapwQtU84iWk= +github.com/emicklei/go-restful/v3 v3.12.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= @@ -108,8 +108,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= -github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U= -github.com/evanphx/json-patch v5.6.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= +github.com/evanphx/json-patch v5.7.0+incompatible h1:vgGkfT/9f8zE6tvSCe74nfpAVDQ2tG6yudJd8LBksgI= +github.com/evanphx/json-patch v5.7.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg= github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ= github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= @@ -247,8 +247,8 @@ github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLe github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4= -github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4= +github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So= @@ -422,6 +422,7 @@ github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.keploy.io/server v0.1.8/go.mod h1:ZqhwTZOBb+dzx5t30Wt6eUGI6kO5QizvPg6coNPtbow= go.mongodb.org/mongo-driver v1.8.0/go.mod h1:0sQWfOeY63QTntERDJJ/0SuKK0T1uVSgKCuAROlKEPY= go.mongodb.org/mongo-driver v1.8.1/go.mod h1:0sQWfOeY63QTntERDJJ/0SuKK0T1uVSgKCuAROlKEPY= @@ -497,6 +498,7 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -541,6 +543,7 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20211209124913-491a49abca63/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -555,8 +558,8 @@ golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= -golang.org/x/oauth2 v0.14.0 h1:P0Vrf/2538nmC0H+pEQ3MNFRRnVR7RlqyVw+bvm26z0= -golang.org/x/oauth2 v0.14.0/go.mod h1:lAtNWgaWfL4cm7j2OV8TxGi9Qb7ECORx8DktCY74OwM= +golang.org/x/oauth2 v0.18.0 h1:09qnuIAgzdx1XplqJvW6CQqMCtGZykZWcXzPMPUusvI= +golang.org/x/oauth2 v0.18.0/go.mod h1:Wf7knwG0MPoWIMMBgFlEaSUDaKskp0dCfrlJRJXbBi8= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -568,6 +571,7 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -625,6 +629,8 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= @@ -641,6 +647,7 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -648,8 +655,8 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxb golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20220210224613-90d013bbcef8/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4= -golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= +golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190125232054-d66bd3c5d5a6/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -706,6 +713,7 @@ golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc= golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -741,8 +749,9 @@ google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= +google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= diff --git a/api/v1alpha1/aws_node_types.go b/api/v1alpha1/aws_node_types.go index 15b9967af..2a66d3fef 100644 --- a/api/v1alpha1/aws_node_types.go +++ b/api/v1alpha1/aws_node_types.go @@ -3,29 +3,42 @@ package v1alpha1 -import ( - v1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" - "k8s.io/utils/ptr" - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" +const ( + AWSControlPlaneInstanceType = "m5.xlarge" + AWSWorkerInstanceType = "m5.2xlarge" - "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/variables" + AWSControlPlaneInstanceProfile = "control-plane.cluster-api-provider-aws.sigs.k8s.io" + AWSWorkerInstanceProfile = "nodes.cluster-api-provider-aws.sigs.k8s.io" ) -const ( - AWSControlPlaneInstanceType InstanceType = "m5.xlarge" - AWSWorkerInstanceType InstanceType = "m5.2xlarge" +type AWSControlPlaneNodeSpec struct { + // The IAM instance profile to use for the cluster Machines. + // +kubebuilder:default=control-plane.cluster-api-provider-aws.sigs.k8s.io + // +optional + IAMInstanceProfile string `json:"iamInstanceProfile,omitempty"` - AWSControlPlaneInstanceProfile IAMInstanceProfile = "control-plane.cluster-api-provider-aws.sigs.k8s.io" - AWSWorkerInstanceProfile IAMInstanceProfile = "nodes.cluster-api-provider-aws.sigs.k8s.io" -) + // +kubebuilder:default=m5.xlarge + // +optional + InstanceType string `json:"instanceType,omitempty"` + + AWSGenericNodeSpec `json:",inline"` +} -type AWSNodeSpec struct { +type AWSWorkerNodeSpec struct { + // The IAM instance profile to use for the cluster Machines. + // +kubebuilder:default=nodes.cluster-api-provider-aws.sigs.k8s.io // +optional - IAMInstanceProfile *IAMInstanceProfile `json:"iamInstanceProfile,omitempty"` + IAMInstanceProfile string `json:"iamInstanceProfile,omitempty"` + // The AWS instance type to use for the cluster Machines. + // +kubebuilder:default=m5.2xlarge // +optional - InstanceType *InstanceType `json:"instanceType,omitempty"` + InstanceType string `json:"instanceType,omitempty"` + AWSGenericNodeSpec `json:",inline"` +} + +type AWSGenericNodeSpec struct { // AMI or AMI Lookup arguments for machine image of a AWS machine. // If both AMI ID and AMI lookup arguments are provided then AMI ID takes precedence //+optional @@ -35,87 +48,16 @@ type AWSNodeSpec struct { AdditionalSecurityGroups AdditionalSecurityGroup `json:"additionalSecurityGroups,omitempty"` } -func NewAWSControlPlaneNodeSpec() *AWSNodeSpec { - return &AWSNodeSpec{ - InstanceType: ptr.To(AWSControlPlaneInstanceType), - IAMInstanceProfile: ptr.To(AWSControlPlaneInstanceProfile), - } -} - -func NewAWSWorkerNodeSpec() *AWSNodeSpec { - return &AWSNodeSpec{ - InstanceType: ptr.To(AWSWorkerInstanceType), - IAMInstanceProfile: ptr.To(AWSWorkerInstanceProfile), - } -} - type AdditionalSecurityGroup []SecurityGroup type SecurityGroup struct { // ID is the id of the security group // +optional - ID *string `json:"id,omitempty"` -} - -func (AdditionalSecurityGroup) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "array", - Items: &clusterv1.JSONSchemaProps{ - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "id": { - Type: "string", - Description: "Security group ID to add for the cluster Machines", - }, - }, - }, - }, - } -} - -func (a AWSNodeSpec) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "AWS Node configuration", - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{ - "iamInstanceProfile": a.IAMInstanceProfile.VariableSchema().OpenAPIV3Schema, - "instanceType": a.InstanceType.VariableSchema().OpenAPIV3Schema, - "ami": AMISpec{}.VariableSchema().OpenAPIV3Schema, - "additionalSecurityGroups": AdditionalSecurityGroup{}.VariableSchema().OpenAPIV3Schema, - }, - Required: []string{"instanceType"}, - }, - } -} - -type IAMInstanceProfile string - -func (i IAMInstanceProfile) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "string", - Description: "The IAM instance profile to use for the cluster Machines", - Default: variables.MustMarshal(i), - }, - } -} - -type InstanceType string - -func (i InstanceType) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "string", - Description: "The AWS instance type to use for the cluster Machines", - Default: variables.MustMarshal(i), - }, - } + ID string `json:"id,omitempty"` } type AMISpec struct { - // ID is an explicit AMI to use. + // AMI ID is the reference to the AMI from which to create the machine instance. // +optional ID string `json:"id,omitempty"` @@ -124,58 +66,18 @@ type AMISpec struct { Lookup *AMILookup `json:"lookup,omitempty"` } -func (AMISpec) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "object", - Default: &v1.JSON{}, - Description: "AMI or AMI Lookup arguments for machine image of a AWS machine." + - "If both AMI ID and AMI lookup arguments are provided then AMI ID takes precedence", - Properties: map[string]clusterv1.JSONSchemaProps{ - "id": { - Type: "string", - Description: "AMI ID is the reference to the AMI from which to create the machine instance.", - }, - "lookup": AMILookup{}.VariableSchema().OpenAPIV3Schema, - }, - }, - } -} - type AMILookup struct { - // Format is the AMI naming format + // AMI naming format. Supports substitutions for {{.BaseOS}} and {{.K8sVersion}} with the + // base OS and kubernetes version. + // +kubebuilder:example=`capa-ami-{{.BaseOS}}-?{{.K8sVersion}}-*` // +optional Format string `json:"format,omitempty"` - // Org is the AWS Organization ID to use for image lookup + // The AWS Organization ID to use for image lookup. // +optional Org string `json:"org,omitempty"` - // BaseOS is the name of the base os for image lookup + // The name of the base os for image lookup // +optional BaseOS string `json:"baseOS,omitempty"` } - -func (AMILookup) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Type: "object", - Default: &v1.JSON{}, - Properties: map[string]clusterv1.JSONSchemaProps{ - "format": { - Type: "string", - Description: "AMI naming format. Supports substitutions for {{.BaseOS}} and {{.K8sVersion}} with the" + - "base OS and kubernetes version. example: capa-ami-{{.BaseOS}}-?{{.K8sVersion}}-*", - }, - "org": { - Type: "string", - Description: "The AWS Organization ID to use for image lookup", - }, - "baseOS": { - Type: "string", - Description: "The name of the base os for image lookup", - }, - }, - }, - } -} diff --git a/api/v1alpha1/clusterconfig_types.go b/api/v1alpha1/clusterconfig_types.go index 5710246c1..caeb673af 100644 --- a/api/v1alpha1/clusterconfig_types.go +++ b/api/v1alpha1/clusterconfig_types.go @@ -84,7 +84,7 @@ type AWSClusterConfigSpec struct { GenericClusterConfigSpec `json:",inline"` // +optional - ControlPlane *AWSNodeConfigSpec `json:"controlPlane,omitempty"` + ControlPlane *AWSControlPlaneNodeConfigSpec `json:"controlPlane,omitempty"` // Extra Subject Alternative Names for the API Server signing cert. // +kubebuilder:validation:UniqueItems=true diff --git a/api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml index d31bed946..14ec91fc4 100644 --- a/api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml +++ b/api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml @@ -247,7 +247,7 @@ spec: type: object controlPlane: description: |- - AWSNodeConfigSpec defines the desired state of AWSNodeConfig. + AWSControlPlaneConfigSpec defines the desired state of AWSNodeConfig. Place any configuration that can be applied to individual Nodes here. Otherwise, it should go into the ClusterConfigSpec. properties: @@ -267,27 +267,34 @@ spec: If both AMI ID and AMI lookup arguments are provided then AMI ID takes precedence properties: id: - description: ID is an explicit AMI to use. + description: AMI ID is the reference to the AMI from which + to create the machine instance. type: string lookup: description: Lookup is the lookup arguments for the AMI. properties: baseOS: - description: BaseOS is the name of the base os for - image lookup + description: The name of the base os for image lookup type: string format: - description: Format is the AMI naming format + description: |- + AMI naming format. Supports substitutions for {{.BaseOS}} and {{.K8sVersion}} with the + base OS and kubernetes version. + example: capa-ami-{{.BaseOS}}-?{{.K8sVersion}}-* type: string org: - description: Org is the AWS Organization ID to use - for image lookup + description: The AWS Organization ID to use for image + lookup. type: string type: object type: object iamInstanceProfile: + default: control-plane.cluster-api-provider-aws.sigs.k8s.io + description: The IAM instance profile to use for the cluster + Machines. type: string instanceType: + default: m5.xlarge type: string type: object type: object diff --git a/api/v1alpha1/crds/caren.nutanix.com_awsnodeconfigs.yaml b/api/v1alpha1/crds/caren.nutanix.com_awsworkernodeconfigs.yaml similarity index 69% rename from api/v1alpha1/crds/caren.nutanix.com_awsnodeconfigs.yaml rename to api/v1alpha1/crds/caren.nutanix.com_awsworkernodeconfigs.yaml index f019bb5d5..76512b4e7 100644 --- a/api/v1alpha1/crds/caren.nutanix.com_awsnodeconfigs.yaml +++ b/api/v1alpha1/crds/caren.nutanix.com_awsworkernodeconfigs.yaml @@ -6,20 +6,20 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: (devel) - name: awsnodeconfigs.caren.nutanix.com + name: awsworkernodeconfigs.caren.nutanix.com spec: group: caren.nutanix.com names: - kind: AWSNodeConfig - listKind: AWSNodeConfigList - plural: awsnodeconfigs - singular: awsnodeconfig + kind: AWSWorkerNodeConfig + listKind: AWSWorkerNodeConfigList + plural: awsworkernodeconfigs + singular: awsworkernodeconfig scope: Namespaced versions: - name: v1alpha1 schema: openAPIV3Schema: - description: AWSNodeConfig is the Schema for the awsnodeconfigs API. + description: AWSWorkerNodeConfig is the Schema for the awsnodeconfigs API. properties: apiVersion: description: |- @@ -40,7 +40,7 @@ spec: type: object spec: description: |- - AWSNodeConfigSpec defines the desired state of AWSNodeConfig. + AWSWorkerNodeConfigSpec defines the desired state of AWSNodeConfig. Place any configuration that can be applied to individual Nodes here. Otherwise, it should go into the ClusterConfigSpec. properties: @@ -60,27 +60,34 @@ spec: If both AMI ID and AMI lookup arguments are provided then AMI ID takes precedence properties: id: - description: ID is an explicit AMI to use. + description: AMI ID is the reference to the AMI from which + to create the machine instance. type: string lookup: description: Lookup is the lookup arguments for the AMI. properties: baseOS: - description: BaseOS is the name of the base os for image - lookup + description: The name of the base os for image lookup type: string format: - description: Format is the AMI naming format + description: |- + AMI naming format. Supports substitutions for {{.BaseOS}} and {{.K8sVersion}} with the + base OS and kubernetes version. + example: capa-ami-{{.BaseOS}}-?{{.K8sVersion}}-* type: string org: - description: Org is the AWS Organization ID to use for - image lookup + description: The AWS Organization ID to use for image + lookup. type: string type: object type: object iamInstanceProfile: + default: nodes.cluster-api-provider-aws.sigs.k8s.io + description: The IAM instance profile to use for the cluster Machines. type: string instanceType: + default: m5.2xlarge + description: The AWS instance type to use for the cluster Machines. type: string type: object type: object diff --git a/api/v1alpha1/docker_clusterconfig_types.go b/api/v1alpha1/docker_clusterconfig_types.go index 7fbcc8fd3..cc37284cb 100644 --- a/api/v1alpha1/docker_clusterconfig_types.go +++ b/api/v1alpha1/docker_clusterconfig_types.go @@ -3,18 +3,4 @@ package v1alpha1 -import ( - clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" -) - type DockerSpec struct{} - -func (DockerSpec) VariableSchema() clusterv1.VariableSchema { - return clusterv1.VariableSchema{ - OpenAPIV3Schema: clusterv1.JSONSchemaProps{ - Description: "Docker cluster configuration", - Type: "object", - Properties: map[string]clusterv1.JSONSchemaProps{}, - }, - } -} diff --git a/api/v1alpha1/nodeconfig_types.go b/api/v1alpha1/nodeconfig_types.go index eaae20980..4125ece69 100644 --- a/api/v1alpha1/nodeconfig_types.go +++ b/api/v1alpha1/nodeconfig_types.go @@ -15,39 +15,49 @@ import ( var ( //go:embed crds/caren.nutanix.com_dockernodeconfigs.yaml dockerNodeConfigCRDDefinition []byte - //go:embed crds/caren.nutanix.com_awsnodeconfigs.yaml + //go:embed crds/caren.nutanix.com_awsworkernodeconfigs.yaml awsNodeConfigCRDDefinition []byte //go:embed crds/caren.nutanix.com_nutanixnodeconfigs.yaml nutanixNodeConfigCRDDefinition []byte - dockerNodeConfigVariableSchema = variables.MustSchemaFromCRDYAML(dockerNodeConfigCRDDefinition) - awsNodeConfigVariableSchema = variables.MustSchemaFromCRDYAML(awsNodeConfigCRDDefinition) - nutanixNodeConfigVariableSchema = variables.MustSchemaFromCRDYAML( + dockerNodeConfigVariableSchema = variables.MustSchemaFromCRDYAML( + dockerNodeConfigCRDDefinition, + ) + awsWorkerNodeConfigVariableSchema = variables.MustSchemaFromCRDYAML(awsNodeConfigCRDDefinition) + nutanixNodeConfigVariableSchema = variables.MustSchemaFromCRDYAML( nutanixNodeConfigCRDDefinition, ) ) // +kubebuilder:object:root=true -// AWSNodeConfig is the Schema for the awsnodeconfigs API. -type AWSNodeConfig struct { +// AWSWorkerNodeConfig is the Schema for the awsnodeconfigs API. +type AWSWorkerNodeConfig struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` //+optional - Spec AWSNodeConfigSpec `json:"spec,omitempty"` + Spec AWSWorkerNodeConfigSpec `json:"spec,omitempty"` +} + +func (s AWSWorkerNodeConfig) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect. + return awsWorkerNodeConfigVariableSchema } -func (s AWSNodeConfig) VariableSchema() clusterv1.VariableSchema { //nolint:gocritic,lll // Passed by value for no potential side-effect. - return awsNodeConfigVariableSchema +// AWSWorkerNodeConfigSpec defines the desired state of AWSNodeConfig. +// Place any configuration that can be applied to individual Nodes here. +// Otherwise, it should go into the ClusterConfigSpec. +type AWSWorkerNodeConfigSpec struct { + // +optional + AWS *AWSWorkerNodeSpec `json:"aws,omitempty"` } -// AWSNodeConfigSpec defines the desired state of AWSNodeConfig. +// AWSControlPlaneConfigSpec defines the desired state of AWSNodeConfig. // Place any configuration that can be applied to individual Nodes here. // Otherwise, it should go into the ClusterConfigSpec. -type AWSNodeConfigSpec struct { +type AWSControlPlaneNodeConfigSpec struct { // +optional - AWS *AWSNodeSpec `json:"aws,omitempty"` + AWS *AWSControlPlaneNodeSpec `json:"aws,omitempty"` } // +kubebuilder:object:root=true @@ -93,5 +103,5 @@ type NutanixNodeConfigSpec struct { } func init() { - SchemeBuilder.Register(&AWSNodeConfig{}, &DockerNodeConfig{}, &NutanixNodeConfig{}) + SchemeBuilder.Register(&AWSWorkerNodeConfig{}, &DockerNodeConfig{}, &NutanixNodeConfig{}) } diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 936e25966..e90666c33 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -85,7 +85,7 @@ func (in *AWSClusterConfigSpec) DeepCopyInto(out *AWSClusterConfigSpec) { in.GenericClusterConfigSpec.DeepCopyInto(&out.GenericClusterConfigSpec) if in.ControlPlane != nil { in, out := &in.ControlPlane, &out.ControlPlane - *out = new(AWSNodeConfigSpec) + *out = new(AWSControlPlaneNodeConfigSpec) (*in).DeepCopyInto(*out) } if in.ExtraAPIServerCertSANs != nil { @@ -105,6 +105,67 @@ func (in *AWSClusterConfigSpec) DeepCopy() *AWSClusterConfigSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AWSControlPlaneNodeConfigSpec) DeepCopyInto(out *AWSControlPlaneNodeConfigSpec) { + *out = *in + if in.AWS != nil { + in, out := &in.AWS, &out.AWS + *out = new(AWSControlPlaneNodeSpec) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AWSControlPlaneNodeConfigSpec. +func (in *AWSControlPlaneNodeConfigSpec) DeepCopy() *AWSControlPlaneNodeConfigSpec { + if in == nil { + return nil + } + out := new(AWSControlPlaneNodeConfigSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AWSControlPlaneNodeSpec) DeepCopyInto(out *AWSControlPlaneNodeSpec) { + *out = *in + in.AWSGenericNodeSpec.DeepCopyInto(&out.AWSGenericNodeSpec) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AWSControlPlaneNodeSpec. +func (in *AWSControlPlaneNodeSpec) DeepCopy() *AWSControlPlaneNodeSpec { + if in == nil { + return nil + } + out := new(AWSControlPlaneNodeSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AWSGenericNodeSpec) DeepCopyInto(out *AWSGenericNodeSpec) { + *out = *in + if in.AMISpec != nil { + in, out := &in.AMISpec, &out.AMISpec + *out = new(AMISpec) + (*in).DeepCopyInto(*out) + } + if in.AdditionalSecurityGroups != nil { + in, out := &in.AdditionalSecurityGroups, &out.AdditionalSecurityGroups + *out = make(AdditionalSecurityGroup, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AWSGenericNodeSpec. +func (in *AWSGenericNodeSpec) DeepCopy() *AWSGenericNodeSpec { + if in == nil { + return nil + } + out := new(AWSGenericNodeSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *AWSLoadBalancerSpec) DeepCopyInto(out *AWSLoadBalancerSpec) { *out = *in @@ -151,25 +212,55 @@ func (in *AWSNetwork) DeepCopy() *AWSNetwork { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *AWSNodeConfig) DeepCopyInto(out *AWSNodeConfig) { +func (in *AWSSpec) DeepCopyInto(out *AWSSpec) { + *out = *in + if in.Region != nil { + in, out := &in.Region, &out.Region + *out = new(Region) + **out = **in + } + if in.Network != nil { + in, out := &in.Network, &out.Network + *out = new(AWSNetwork) + (*in).DeepCopyInto(*out) + } + if in.ControlPlaneLoadBalancer != nil { + in, out := &in.ControlPlaneLoadBalancer, &out.ControlPlaneLoadBalancer + *out = new(AWSLoadBalancerSpec) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AWSSpec. +func (in *AWSSpec) DeepCopy() *AWSSpec { + if in == nil { + return nil + } + out := new(AWSSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AWSWorkerNodeConfig) DeepCopyInto(out *AWSWorkerNodeConfig) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) in.Spec.DeepCopyInto(&out.Spec) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AWSNodeConfig. -func (in *AWSNodeConfig) DeepCopy() *AWSNodeConfig { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AWSWorkerNodeConfig. +func (in *AWSWorkerNodeConfig) DeepCopy() *AWSWorkerNodeConfig { if in == nil { return nil } - out := new(AWSNodeConfig) + out := new(AWSWorkerNodeConfig) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *AWSNodeConfig) DeepCopyObject() runtime.Object { +func (in *AWSWorkerNodeConfig) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -177,88 +268,37 @@ func (in *AWSNodeConfig) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *AWSNodeConfigSpec) DeepCopyInto(out *AWSNodeConfigSpec) { +func (in *AWSWorkerNodeConfigSpec) DeepCopyInto(out *AWSWorkerNodeConfigSpec) { *out = *in if in.AWS != nil { in, out := &in.AWS, &out.AWS - *out = new(AWSNodeSpec) + *out = new(AWSWorkerNodeSpec) (*in).DeepCopyInto(*out) } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AWSNodeConfigSpec. -func (in *AWSNodeConfigSpec) DeepCopy() *AWSNodeConfigSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AWSWorkerNodeConfigSpec. +func (in *AWSWorkerNodeConfigSpec) DeepCopy() *AWSWorkerNodeConfigSpec { if in == nil { return nil } - out := new(AWSNodeConfigSpec) + out := new(AWSWorkerNodeConfigSpec) in.DeepCopyInto(out) return out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *AWSNodeSpec) DeepCopyInto(out *AWSNodeSpec) { +func (in *AWSWorkerNodeSpec) DeepCopyInto(out *AWSWorkerNodeSpec) { *out = *in - if in.IAMInstanceProfile != nil { - in, out := &in.IAMInstanceProfile, &out.IAMInstanceProfile - *out = new(IAMInstanceProfile) - **out = **in - } - if in.InstanceType != nil { - in, out := &in.InstanceType, &out.InstanceType - *out = new(InstanceType) - **out = **in - } - if in.AMISpec != nil { - in, out := &in.AMISpec, &out.AMISpec - *out = new(AMISpec) - (*in).DeepCopyInto(*out) - } - if in.AdditionalSecurityGroups != nil { - in, out := &in.AdditionalSecurityGroups, &out.AdditionalSecurityGroups - *out = make(AdditionalSecurityGroup, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } + in.AWSGenericNodeSpec.DeepCopyInto(&out.AWSGenericNodeSpec) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AWSNodeSpec. -func (in *AWSNodeSpec) DeepCopy() *AWSNodeSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AWSWorkerNodeSpec. +func (in *AWSWorkerNodeSpec) DeepCopy() *AWSWorkerNodeSpec { if in == nil { return nil } - out := new(AWSNodeSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *AWSSpec) DeepCopyInto(out *AWSSpec) { - *out = *in - if in.Region != nil { - in, out := &in.Region, &out.Region - *out = new(Region) - **out = **in - } - if in.Network != nil { - in, out := &in.Network, &out.Network - *out = new(AWSNetwork) - (*in).DeepCopyInto(*out) - } - if in.ControlPlaneLoadBalancer != nil { - in, out := &in.ControlPlaneLoadBalancer, &out.ControlPlaneLoadBalancer - *out = new(AWSLoadBalancerSpec) - (*in).DeepCopyInto(*out) - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AWSSpec. -func (in *AWSSpec) DeepCopy() *AWSSpec { - if in == nil { - return nil - } - out := new(AWSSpec) + out := new(AWSWorkerNodeSpec) in.DeepCopyInto(out) return out } @@ -268,9 +308,7 @@ func (in AdditionalSecurityGroup) DeepCopyInto(out *AdditionalSecurityGroup) { { in := &in *out = make(AdditionalSecurityGroup, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } + copy(*out, *in) } } @@ -1070,11 +1108,6 @@ func (in *RegistryCredentials) DeepCopy() *RegistryCredentials { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SecurityGroup) DeepCopyInto(out *SecurityGroup) { *out = *in - if in.ID != nil { - in, out := &in.ID, &out.ID - *out = new(string) - **out = **in - } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SecurityGroup. diff --git a/pkg/handlers/aws/mutation/ami/variables_test.go b/pkg/handlers/aws/mutation/ami/variables_test.go index ed6392086..a95b9ed57 100644 --- a/pkg/handlers/aws/mutation/ami/variables_test.go +++ b/pkg/handlers/aws/mutation/ami/variables_test.go @@ -24,14 +24,16 @@ func TestVariableValidation(t *testing.T) { capitest.VariableTestDef{ Name: "AMI specification", Vals: v1alpha1.AWSClusterConfigSpec{ - ControlPlane: &v1alpha1.AWSNodeConfigSpec{ - AWS: &v1alpha1.AWSNodeSpec{ - AMISpec: &v1alpha1.AMISpec{ - ID: "ami-1234", - Lookup: &v1alpha1.AMILookup{ - Format: "capa-ami-{{.BaseOS}}-?{{.K8sVersion}}-*", - BaseOS: "rhel-8.4", - Org: "12345678", + ControlPlane: &v1alpha1.AWSControlPlaneNodeConfigSpec{ + AWS: &v1alpha1.AWSControlPlaneNodeSpec{ + AWSGenericNodeSpec: v1alpha1.AWSGenericNodeSpec{ + AMISpec: &v1alpha1.AMISpec{ + ID: "ami-1234", + Lookup: &v1alpha1.AMILookup{ + Format: "capa-ami-{{.BaseOS}}-?{{.K8sVersion}}-*", + BaseOS: "rhel-8.4", + Org: "12345678", + }, }, }, }, diff --git a/pkg/handlers/aws/mutation/iaminstanceprofile/inject_control_plane.go b/pkg/handlers/aws/mutation/iaminstanceprofile/inject_control_plane.go index 719c102ae..ce73b809e 100644 --- a/pkg/handlers/aws/mutation/iaminstanceprofile/inject_control_plane.go +++ b/pkg/handlers/aws/mutation/iaminstanceprofile/inject_control_plane.go @@ -62,7 +62,7 @@ func (h *awsIAMInstanceProfileControlPlanePatchHandler) Mutate( "holderRef", holderRef, ) - iamInstanceProfileVar, err := variables.Get[v1alpha1.IAMInstanceProfile]( + iamInstanceProfileVar, err := variables.Get[string]( vars, h.variableName, h.variableFieldPath..., @@ -99,7 +99,7 @@ func (h *awsIAMInstanceProfileControlPlanePatchHandler) Mutate( "patchedObjectName", client.ObjectKeyFromObject(obj), ).Info("setting IAM instance profile in control plane AWSMachineTemplate spec") - obj.Spec.Template.Spec.IAMInstanceProfile = string(iamInstanceProfileVar) + obj.Spec.Template.Spec.IAMInstanceProfile = iamInstanceProfileVar return nil }, diff --git a/pkg/handlers/aws/mutation/iaminstanceprofile/inject_worker.go b/pkg/handlers/aws/mutation/iaminstanceprofile/inject_worker.go index 38a1be5ce..8f165f0c9 100644 --- a/pkg/handlers/aws/mutation/iaminstanceprofile/inject_worker.go +++ b/pkg/handlers/aws/mutation/iaminstanceprofile/inject_worker.go @@ -56,7 +56,7 @@ func (h *awsIAMInstanceProfileWorkerPatchHandler) Mutate( "holderRef", holderRef, ) - iamInstanceProfileVar, err := variables.Get[v1alpha1.IAMInstanceProfile]( + iamInstanceProfileVar, err := variables.Get[string]( vars, h.variableName, h.variableFieldPath..., @@ -93,7 +93,7 @@ func (h *awsIAMInstanceProfileWorkerPatchHandler) Mutate( "patchedObjectName", client.ObjectKeyFromObject(obj), ).Info("setting IAM instance profile in worker AWSMachineTemplate spec") - obj.Spec.Template.Spec.IAMInstanceProfile = string(iamInstanceProfileVar) + obj.Spec.Template.Spec.IAMInstanceProfile = iamInstanceProfileVar return nil }, diff --git a/pkg/handlers/aws/mutation/iaminstanceprofile/variables_test.go b/pkg/handlers/aws/mutation/iaminstanceprofile/variables_test.go index 41afe0e97..562280429 100644 --- a/pkg/handlers/aws/mutation/iaminstanceprofile/variables_test.go +++ b/pkg/handlers/aws/mutation/iaminstanceprofile/variables_test.go @@ -24,14 +24,16 @@ func TestVariableValidation(t *testing.T) { capitest.VariableTestDef{ Name: "AMI specification", Vals: v1alpha1.AWSClusterConfigSpec{ - ControlPlane: &v1alpha1.AWSNodeConfigSpec{ - AWS: &v1alpha1.AWSNodeSpec{ - AMISpec: &v1alpha1.AMISpec{ - ID: "ami-1234", - Lookup: &v1alpha1.AMILookup{ - Format: "capa-ami-{{.BaseOS}}-?{{.K8sVersion}}-*", - BaseOS: "rhel-8.4", - Org: "12345678", + ControlPlane: &v1alpha1.AWSControlPlaneNodeConfigSpec{ + AWS: &v1alpha1.AWSControlPlaneNodeSpec{ + AWSGenericNodeSpec: v1alpha1.AWSGenericNodeSpec{ + AMISpec: &v1alpha1.AMISpec{ + ID: "ami-1234", + Lookup: &v1alpha1.AMILookup{ + Format: "capa-ami-{{.BaseOS}}-?{{.K8sVersion}}-*", + BaseOS: "rhel-8.4", + Org: "12345678", + }, }, }, }, diff --git a/pkg/handlers/aws/mutation/instancetype/inject_control_plane.go b/pkg/handlers/aws/mutation/instancetype/inject_control_plane.go index ed4ebaaeb..10f330af3 100644 --- a/pkg/handlers/aws/mutation/instancetype/inject_control_plane.go +++ b/pkg/handlers/aws/mutation/instancetype/inject_control_plane.go @@ -62,7 +62,7 @@ func (h *awsInstanceTypeControlPlanePatchHandler) Mutate( "holderRef", holderRef, ) - instanceTypeVar, err := variables.Get[v1alpha1.InstanceType]( + instanceTypeVar, err := variables.Get[string]( vars, h.variableName, h.variableFieldPath..., @@ -99,7 +99,7 @@ func (h *awsInstanceTypeControlPlanePatchHandler) Mutate( "patchedObjectName", client.ObjectKeyFromObject(obj), ).Info("setting instance type in control plane AWSMachineTemplate spec") - obj.Spec.Template.Spec.InstanceType = string(instanceTypeVar) + obj.Spec.Template.Spec.InstanceType = instanceTypeVar return nil }, diff --git a/pkg/handlers/aws/mutation/instancetype/inject_worker.go b/pkg/handlers/aws/mutation/instancetype/inject_worker.go index 3deb4ce58..b439721da 100644 --- a/pkg/handlers/aws/mutation/instancetype/inject_worker.go +++ b/pkg/handlers/aws/mutation/instancetype/inject_worker.go @@ -56,7 +56,7 @@ func (h *awsInstanceTypeWorkerPatchHandler) Mutate( "holderRef", holderRef, ) - instanceTypeVar, err := variables.Get[v1alpha1.InstanceType]( + instanceTypeVar, err := variables.Get[string]( vars, h.variableName, h.variableFieldPath..., @@ -93,7 +93,7 @@ func (h *awsInstanceTypeWorkerPatchHandler) Mutate( "patchedObjectName", client.ObjectKeyFromObject(obj), ).Info("setting instance type in workers AWSMachineTemplate spec") - obj.Spec.Template.Spec.InstanceType = string(instanceTypeVar) + obj.Spec.Template.Spec.InstanceType = instanceTypeVar return nil }, diff --git a/pkg/handlers/aws/mutation/instancetype/variables_test.go b/pkg/handlers/aws/mutation/instancetype/variables_test.go index a91e10294..0dcc81360 100644 --- a/pkg/handlers/aws/mutation/instancetype/variables_test.go +++ b/pkg/handlers/aws/mutation/instancetype/variables_test.go @@ -24,9 +24,9 @@ func TestVariableValidation(t *testing.T) { capitest.VariableTestDef{ Name: "specified instance type", Vals: v1alpha1.AWSClusterConfigSpec{ - ControlPlane: &v1alpha1.AWSNodeConfigSpec{ - AWS: &v1alpha1.AWSNodeSpec{ - InstanceType: ptr.To(v1alpha1.InstanceType("m5.small")), + ControlPlane: &v1alpha1.AWSControlPlaneNodeConfigSpec{ + AWS: &v1alpha1.AWSControlPlaneNodeSpec{ + InstanceType: "m5.small", }, }, }, diff --git a/pkg/handlers/aws/mutation/securitygroups/inject.go b/pkg/handlers/aws/mutation/securitygroups/inject.go index 7853285b5..b76ba61ac 100644 --- a/pkg/handlers/aws/mutation/securitygroups/inject.go +++ b/pkg/handlers/aws/mutation/securitygroups/inject.go @@ -8,6 +8,7 @@ import ( apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + "k8s.io/utils/ptr" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" ctrl "sigs.k8s.io/controller-runtime" @@ -79,7 +80,7 @@ func (h *awsSecurityGroupSpecPatchHandler) Mutate( resourceRefs := make([]capav1.AWSResourceReference, 0, len(additionalSecGroupVar)) for _, secGroup := range additionalSecGroupVar { resourceRefs = append(resourceRefs, capav1.AWSResourceReference{ - ID: secGroup.ID, + ID: ptr.To(secGroup.ID), }) } return patches.MutateIfApplicable( diff --git a/pkg/handlers/aws/mutation/securitygroups/inject_control_plane_test.go b/pkg/handlers/aws/mutation/securitygroups/inject_control_plane_test.go index ef157d137..cd54f405e 100644 --- a/pkg/handlers/aws/mutation/securitygroups/inject_control_plane_test.go +++ b/pkg/handlers/aws/mutation/securitygroups/inject_control_plane_test.go @@ -6,7 +6,6 @@ package securitygroups import ( . "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" - "k8s.io/utils/ptr" runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" @@ -36,9 +35,9 @@ var _ = Describe("Generate SecurityGroup patches for ControlPlane", func() { capitest.VariableWithValue( clusterconfig.MetaVariableName, v1alpha1.AdditionalSecurityGroup{ - {ID: ptr.To("sg-1")}, - {ID: ptr.To("sg-2")}, - {ID: ptr.To("sg-3")}, + {ID: "sg-1"}, + {ID: "sg-2"}, + {ID: "sg-3"}, }, clusterconfig.MetaControlPlaneConfigName, v1alpha1.AWSVariableName, diff --git a/pkg/handlers/aws/mutation/securitygroups/inject_worker_test.go b/pkg/handlers/aws/mutation/securitygroups/inject_worker_test.go index 1755e94b8..701fc8e70 100644 --- a/pkg/handlers/aws/mutation/securitygroups/inject_worker_test.go +++ b/pkg/handlers/aws/mutation/securitygroups/inject_worker_test.go @@ -7,7 +7,6 @@ import ( . "github.com/onsi/ginkgo/v2" "github.com/onsi/gomega" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" - "k8s.io/utils/ptr" runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" "github.com/nutanix-cloud-native/cluster-api-runtime-extensions-nutanix/api/v1alpha1" @@ -33,9 +32,9 @@ var _ = Describe("Generate AWS SecurityGroups patches for Worker", func() { capitest.VariableWithValue( workerconfig.MetaVariableName, v1alpha1.AdditionalSecurityGroup{ - {ID: ptr.To("sg-1")}, - {ID: ptr.To("sg-2")}, - {ID: ptr.To("sg-3")}, + {ID: "sg-1"}, + {ID: "sg-2"}, + {ID: "sg-3"}, }, v1alpha1.AWSVariableName, VariableName, diff --git a/pkg/handlers/aws/mutation/securitygroups/variables_test.go b/pkg/handlers/aws/mutation/securitygroups/variables_test.go index b7e3646a3..661c46d65 100644 --- a/pkg/handlers/aws/mutation/securitygroups/variables_test.go +++ b/pkg/handlers/aws/mutation/securitygroups/variables_test.go @@ -24,14 +24,16 @@ func TestVariableValidation(t *testing.T) { capitest.VariableTestDef{ Name: "Additional Security Group Specification", Vals: v1alpha1.AWSClusterConfigSpec{ - ControlPlane: &v1alpha1.AWSNodeConfigSpec{ - AWS: &v1alpha1.AWSNodeSpec{ - AdditionalSecurityGroups: v1alpha1.AdditionalSecurityGroup{ - { - ID: ptr.To("sg-1234"), - }, - { - ID: ptr.To("sg-0420"), + ControlPlane: &v1alpha1.AWSControlPlaneNodeConfigSpec{ + AWS: &v1alpha1.AWSControlPlaneNodeSpec{ + AWSGenericNodeSpec: v1alpha1.AWSGenericNodeSpec{ + AdditionalSecurityGroups: v1alpha1.AdditionalSecurityGroup{ + { + ID: "sg-1234", + }, + { + ID: "sg-0420", + }, }, }, }, diff --git a/pkg/handlers/aws/workerconfig/variables.go b/pkg/handlers/aws/workerconfig/variables.go index bedcc34f4..7e451e90f 100644 --- a/pkg/handlers/aws/workerconfig/variables.go +++ b/pkg/handlers/aws/workerconfig/variables.go @@ -43,7 +43,7 @@ func (h *awsWorkerConfigVariableHandler) DiscoverVariables( resp.Variables = append(resp.Variables, clusterv1.ClusterClassVariable{ Name: workerconfig.MetaVariableName, Required: false, - Schema: v1alpha1.AWSNodeConfig{}.VariableSchema(), + Schema: v1alpha1.AWSWorkerNodeConfig{}.VariableSchema(), }) resp.SetStatus(runtimehooksv1.ResponseStatusSuccess) } diff --git a/pkg/handlers/aws/workerconfig/variables_test.go b/pkg/handlers/aws/workerconfig/variables_test.go index 4577e85a5..6e59abfb6 100644 --- a/pkg/handlers/aws/workerconfig/variables_test.go +++ b/pkg/handlers/aws/workerconfig/variables_test.go @@ -17,23 +17,23 @@ func TestVariableValidation(t *testing.T) { capitest.ValidateDiscoverVariables( t, workerconfig.MetaVariableName, - ptr.To(v1alpha1.AWSNodeConfig{}.VariableSchema()), + ptr.To(v1alpha1.AWSWorkerNodeConfig{}.VariableSchema()), false, NewVariable, capitest.VariableTestDef{ Name: "specified IAM instance profile", - Vals: v1alpha1.AWSNodeConfigSpec{ - AWS: &v1alpha1.AWSNodeSpec{ - IAMInstanceProfile: ptr.To( - v1alpha1.IAMInstanceProfile("nodes.cluster-api-provider-aws.sigs.k8s.io"), - ), + Vals: v1alpha1.AWSWorkerNodeConfigSpec{ + AWS: &v1alpha1.AWSWorkerNodeSpec{ + IAMInstanceProfile: "nodes.cluster-api-provider-aws.sigs.k8s.io", }, }, }, capitest.VariableTestDef{ Name: "specified instance type", - Vals: v1alpha1.AWSNodeConfigSpec{ - AWS: &v1alpha1.AWSNodeSpec{InstanceType: ptr.To(v1alpha1.InstanceType("m5.small"))}, + Vals: v1alpha1.AWSWorkerNodeConfigSpec{ + AWS: &v1alpha1.AWSWorkerNodeSpec{ + InstanceType: "m5.small", + }, }, }, ) From 91ea6f21289fe2496e43d292a1ae16352883a3ca Mon Sep 17 00:00:00 2001 From: Jimmi Dyson Date: Fri, 19 Apr 2024 09:55:38 +0100 Subject: [PATCH 5/6] revert: Accidentally reverted changes from separate PR --- api/v1alpha1/nutanix_node_types.go | 4 +- api/v1alpha1/zz_generated.deepcopy.go | 53 ++++++++------------------- hack/flakes/flake.lock | 6 +-- 3 files changed, 20 insertions(+), 43 deletions(-) diff --git a/api/v1alpha1/nutanix_node_types.go b/api/v1alpha1/nutanix_node_types.go index 164afc5f3..5b8ddbe6b 100644 --- a/api/v1alpha1/nutanix_node_types.go +++ b/api/v1alpha1/nutanix_node_types.go @@ -33,7 +33,7 @@ type NutanixMachineDetails struct { // subnet identifies the network subnet to use for the machine. // The identifier (uuid or name) can be obtained from the console or API. - Subnets NutanixResourceIdentifiers `json:"subnets"` + Subnets []NutanixResourceIdentifier `json:"subnets"` // List of categories that need to be added to the machines. Categories must already // exist in Prism Central. One category key can have more than one value. @@ -64,5 +64,3 @@ type NutanixBootType capxv1.NutanixBootType type NutanixResourceIdentifier capxv1.NutanixResourceIdentifier type NutanixCategoryIdentifier capxv1.NutanixCategoryIdentifier - -type NutanixResourceIdentifiers []NutanixResourceIdentifier diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index e90666c33..d447db035 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -798,6 +798,21 @@ func (in *NFD) DeepCopy() *NFD { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NutanixCategoryIdentifier) DeepCopyInto(out *NutanixCategoryIdentifier) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NutanixCategoryIdentifier. +func (in *NutanixCategoryIdentifier) DeepCopy() *NutanixCategoryIdentifier { + if in == nil { + return nil + } + out := new(NutanixCategoryIdentifier) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NutanixClusterConfig) DeepCopyInto(out *NutanixClusterConfig) { *out = *in @@ -855,21 +870,6 @@ func (in *NutanixClusterConfigSpec) DeepCopy() *NutanixClusterConfigSpec { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *NutanixCategoryIdentifier) DeepCopyInto(out *NutanixCategoryIdentifier) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NutanixCategoryIdentifier. -func (in *NutanixCategoryIdentifier) DeepCopy() *NutanixCategoryIdentifier { - if in == nil { - return nil - } - out := new(NutanixCategoryIdentifier) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NutanixMachineDetails) DeepCopyInto(out *NutanixMachineDetails) { *out = *in @@ -878,7 +878,7 @@ func (in *NutanixMachineDetails) DeepCopyInto(out *NutanixMachineDetails) { in.Cluster.DeepCopyInto(&out.Cluster) if in.Subnets != nil { in, out := &in.Subnets, &out.Subnets - *out = make(NutanixResourceIdentifiers, len(*in)) + *out = make([]NutanixResourceIdentifier, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } @@ -1018,27 +1018,6 @@ func (in *NutanixResourceIdentifier) DeepCopy() *NutanixResourceIdentifier { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in NutanixResourceIdentifiers) DeepCopyInto(out *NutanixResourceIdentifiers) { - { - in := &in - *out = make(NutanixResourceIdentifiers, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NutanixResourceIdentifiers. -func (in NutanixResourceIdentifiers) DeepCopy() NutanixResourceIdentifiers { - if in == nil { - return nil - } - out := new(NutanixResourceIdentifiers) - in.DeepCopyInto(out) - return *out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NutanixSpec) DeepCopyInto(out *NutanixSpec) { *out = *in diff --git a/hack/flakes/flake.lock b/hack/flakes/flake.lock index 84a5ef8a3..8fd40d554 100644 --- a/hack/flakes/flake.lock +++ b/hack/flakes/flake.lock @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1710827359, - "narHash": "sha256-/KY8hffTh9SN/tTcDn/FrEiYwTXnU8NKnr4D7/stmmA=", + "lastModified": 1713805509, + "narHash": "sha256-YgSEan4CcrjivCNO5ZNzhg7/8ViLkZ4CB/GrGBVSudo=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "5710127d9693421e78cca4f74fac2db6d67162b1", + "rev": "1e1dc66fe68972a76679644a5577828b6a7e8be4", "type": "github" }, "original": { From 0390f6c5b1e9ce1056c286b1dfb0f1a62b0bd874 Mon Sep 17 00:00:00 2001 From: Jimmi Dyson Date: Tue, 23 Apr 2024 17:36:42 +0100 Subject: [PATCH 6/6] fixup! refactor: Delete unused code --- api/openapi/patterns/anchored.go | 12 ------------ api/openapi/patterns/distribution.go | 24 ------------------------ api/openapi/patterns/dns1123.go | 12 ------------ api/openapi/patterns/generic.go | 9 --------- api/openapi/patterns/net.go | 20 -------------------- api/v1alpha1/aws_node_types.go | 8 -------- 6 files changed, 85 deletions(-) delete mode 100644 api/openapi/patterns/anchored.go delete mode 100644 api/openapi/patterns/distribution.go delete mode 100644 api/openapi/patterns/dns1123.go delete mode 100644 api/openapi/patterns/generic.go delete mode 100644 api/openapi/patterns/net.go diff --git a/api/openapi/patterns/anchored.go b/api/openapi/patterns/anchored.go deleted file mode 100644 index 8f4a36dfe..000000000 --- a/api/openapi/patterns/anchored.go +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2023 D2iQ, Inc. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package patterns - -func Anchored(pattern string) string { - return "^" + pattern + "$" -} - -func HTTPSURL() string { - return `^https://` -} diff --git a/api/openapi/patterns/distribution.go b/api/openapi/patterns/distribution.go deleted file mode 100644 index 5379a6921..000000000 --- a/api/openapi/patterns/distribution.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2023 D2iQ, Inc. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package patterns - -const ( - // See: https://github.com/distribution/reference/blob/v0.5.0/regexp.go#L53 - NameSeparator = `(?:[._]|__|[-]+)` - - // See: https://github.com/distribution/reference/blob/v0.5.0/regexp.go#L123 - PathComponent = Alphanumeric + `(` + NameSeparator + Alphanumeric + `)*` - - // See: https://github.com/distribution/reference/blob/v0.5.0/regexp.go#L125-L130 - ImageRepository = `(` + HostAndOptionalPort + `/)?` + PathComponent + `(/` + PathComponent + `)*` - - // See: https://github.com/distribution/reference/blob/v0.5.0/regexp.go#L68 - ImageTag = `[\w][\w.-]{0,127}` - - // See: https://github.com/distribution/reference/blob/v0.5.0/regexp.go#L81 - ImageDigest = `[A-Za-z][A-Za-z0-9]*(?:[-_+.][A-Za-z][A-Za-z0-9]*)*[:][0-9A-Fa-f]{32,}` - - // See: https://github.com/distribution/reference/blob/v0.5.0/regexp.go#L136C2-L136C14 - ImageReference = ImageRepository + `(:` + ImageTag + `)?` + `(@` + ImageDigest + `)?` -) diff --git a/api/openapi/patterns/dns1123.go b/api/openapi/patterns/dns1123.go deleted file mode 100644 index 3652ce90e..000000000 --- a/api/openapi/patterns/dns1123.go +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2023 D2iQ, Inc. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package patterns - -const ( - // See: https://github.com/kubernetes/apimachinery/blob/v0.28.1/pkg/util/validation/validation.go#L178 - DNS1123Label = `[a-z0-9]([-a-z0-9]*[a-z0-9])?` - - // See: https://github.com/kubernetes/apimachinery/blob/v0.28.1/pkg/util/validation/validation.go#L205 - DNS1123Subdomain = DNS1123Label + `(\.` + DNS1123Label + `)*` -) diff --git a/api/openapi/patterns/generic.go b/api/openapi/patterns/generic.go deleted file mode 100644 index 62d9645ca..000000000 --- a/api/openapi/patterns/generic.go +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2023 D2iQ, Inc. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package patterns - -const ( - // See: https://github.com/distribution/reference/blob/v0.5.0/regexp.go#L44C2-L44C28 - Alphanumeric = `[a-z0-9]+` -) diff --git a/api/openapi/patterns/net.go b/api/openapi/patterns/net.go deleted file mode 100644 index ac3013eb6..000000000 --- a/api/openapi/patterns/net.go +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2023 D2iQ, Inc. All rights reserved. -// SPDX-License-Identifier: Apache-2.0 - -package patterns - -const ( - // See: https://github.com/distribution/reference/blob/v0.5.0/regexp.go#L91 - IPv6 = `\[(?:[a-fA-F0-9:]+)\]` - - Port = `:[0-9]+` - - // See https://github.com/distribution/reference/blob/v0.5.0/regexp.go#L65 - OptionalPort = `(` + Port + `)?` - - // See: https://github.com/distribution/reference/blob/v0.5.0/regexp.go#L106 - Host = `(?:` + DNS1123Subdomain + `|` + IPv6 + `)` - - // See: https://github.com/distribution/reference/blob/v0.5.0/regexp.go#L110 - HostAndOptionalPort = Host + OptionalPort -) diff --git a/api/v1alpha1/aws_node_types.go b/api/v1alpha1/aws_node_types.go index 2a66d3fef..99e1e6987 100644 --- a/api/v1alpha1/aws_node_types.go +++ b/api/v1alpha1/aws_node_types.go @@ -3,14 +3,6 @@ package v1alpha1 -const ( - AWSControlPlaneInstanceType = "m5.xlarge" - AWSWorkerInstanceType = "m5.2xlarge" - - AWSControlPlaneInstanceProfile = "control-plane.cluster-api-provider-aws.sigs.k8s.io" - AWSWorkerInstanceProfile = "nodes.cluster-api-provider-aws.sigs.k8s.io" -) - type AWSControlPlaneNodeSpec struct { // The IAM instance profile to use for the cluster Machines. // +kubebuilder:default=control-plane.cluster-api-provider-aws.sigs.k8s.io