From 0f500bce6786a607af129440eeed13274d930906 Mon Sep 17 00:00:00 2001 From: Danil-Grigorev Date: Thu, 29 Aug 2024 08:52:43 +0200 Subject: [PATCH 1/3] Move rancher types under separate external API package Signed-off-by: Danil-Grigorev --- .golangci.yml | 4 ++-- Makefile | 3 +-- {internal => api}/rancher/doc.go | 0 {internal => api}/rancher/management/v3/cluster.go | 0 .../rancher/management/v3/clusterregistrationtoken.go | 0 {internal => api}/rancher/management/v3/doc.go | 0 {internal => api}/rancher/management/v3/groupversion_info.go | 0 .../rancher/management/v3/zz_generated.deepcopy.go | 0 {internal => api}/rancher/provisioning/v1/cluster.go | 0 {internal => api}/rancher/provisioning/v1/doc.go | 0 .../rancher/provisioning/v1/groupversion_info.go | 0 {internal => api}/rancher/provisioning/v1/rke.go | 0 .../rancher/provisioning/v1/zz_generated.deepcopy.go | 0 docs/adr/0009-use-structured-proxy-types.md | 2 +- internal/controllers/helpers.go | 2 +- internal/controllers/import_controller.go | 4 ++-- internal/controllers/import_controller_test.go | 4 ++-- internal/controllers/import_controller_v3.go | 4 ++-- internal/controllers/import_controller_v3_test.go | 4 ++-- internal/controllers/patch_kcfg_controller.go | 2 +- internal/controllers/patch_kcfg_controller_test.go | 2 +- internal/controllers/suite_test.go | 4 ++-- main.go | 4 ++-- test/e2e/helpers.go | 4 ++-- test/e2e/specs/import_gitops.go | 2 +- test/e2e/specs/import_gitops_mgmtv3.go | 2 +- test/e2e/specs/migrate_gitops_provv1_mgmtv3.go | 4 ++-- test/e2e/suites/update-labels/update_labels_test.go | 2 +- test/e2e/suites/v2prov/v2prov_test.go | 2 +- util/predicates/suite_test.go | 4 ++-- util/predicates/v2prov_predicates.go | 2 +- 31 files changed, 30 insertions(+), 31 deletions(-) rename {internal => api}/rancher/doc.go (100%) rename {internal => api}/rancher/management/v3/cluster.go (100%) rename {internal => api}/rancher/management/v3/clusterregistrationtoken.go (100%) rename {internal => api}/rancher/management/v3/doc.go (100%) rename {internal => api}/rancher/management/v3/groupversion_info.go (100%) rename {internal => api}/rancher/management/v3/zz_generated.deepcopy.go (100%) rename {internal => api}/rancher/provisioning/v1/cluster.go (100%) rename {internal => api}/rancher/provisioning/v1/doc.go (100%) rename {internal => api}/rancher/provisioning/v1/groupversion_info.go (100%) rename {internal => api}/rancher/provisioning/v1/rke.go (100%) rename {internal => api}/rancher/provisioning/v1/zz_generated.deepcopy.go (100%) diff --git a/.golangci.yml b/.golangci.yml index 096726bf..22393be7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -70,9 +70,9 @@ linters-settings: # Rancher Turtles - pkg: github.com/rancher/turtles/util/naming alias: turtlesnaming - - pkg: github.com/rancher/turtles/internal/rancher/provisioning/v1 + - pkg: github.com/rancher/turtles/api/rancher/provisioning/v1 alias: provisioningv1 - - pkg: github.com/rancher/turtles/internal/rancher/management/v3 + - pkg: github.com/rancher/turtles/api/rancher/management/v3 alias: managementv3 # Controller Runtime - pkg: sigs.k8s.io/controller-runtime diff --git a/Makefile b/Makefile index a98675cc..68a95597 100644 --- a/Makefile +++ b/Makefile @@ -226,7 +226,7 @@ manifests: generate .PHONY: generate-manifests-external generate-manifests-external: vendor controller-gen ## Generate ClusterRole and CustomResourceDefinition objects. - $(CONTROLLER_GEN) rbac:roleName=manager-role crd paths="./internal/rancher/..." output:crd:artifacts:config=hack/crd/bases + $(CONTROLLER_GEN) rbac:roleName=manager-role crd paths="./api/rancher/..." output:crd:artifacts:config=hack/crd/bases $(CONTROLLER_GEN) rbac:roleName=manager-role crd paths="./vendor/sigs.k8s.io/cluster-api/..." output:crd:artifacts:config=hack/crd/bases # Vendor is only required for pulling latest CRDs from the dependencies $(MAKE) vendor-clean @@ -258,7 +258,6 @@ generate-go-deepcopy: ## Run deepcopy generation $(CONTROLLER_GEN) \ object:headerFile=./hack/boilerplate.go.txt \ paths=./api/... \ - paths=./internal/rancher/... \ paths=./exp/etcdrestore/api/... # Run go mod diff --git a/internal/rancher/doc.go b/api/rancher/doc.go similarity index 100% rename from internal/rancher/doc.go rename to api/rancher/doc.go diff --git a/internal/rancher/management/v3/cluster.go b/api/rancher/management/v3/cluster.go similarity index 100% rename from internal/rancher/management/v3/cluster.go rename to api/rancher/management/v3/cluster.go diff --git a/internal/rancher/management/v3/clusterregistrationtoken.go b/api/rancher/management/v3/clusterregistrationtoken.go similarity index 100% rename from internal/rancher/management/v3/clusterregistrationtoken.go rename to api/rancher/management/v3/clusterregistrationtoken.go diff --git a/internal/rancher/management/v3/doc.go b/api/rancher/management/v3/doc.go similarity index 100% rename from internal/rancher/management/v3/doc.go rename to api/rancher/management/v3/doc.go diff --git a/internal/rancher/management/v3/groupversion_info.go b/api/rancher/management/v3/groupversion_info.go similarity index 100% rename from internal/rancher/management/v3/groupversion_info.go rename to api/rancher/management/v3/groupversion_info.go diff --git a/internal/rancher/management/v3/zz_generated.deepcopy.go b/api/rancher/management/v3/zz_generated.deepcopy.go similarity index 100% rename from internal/rancher/management/v3/zz_generated.deepcopy.go rename to api/rancher/management/v3/zz_generated.deepcopy.go diff --git a/internal/rancher/provisioning/v1/cluster.go b/api/rancher/provisioning/v1/cluster.go similarity index 100% rename from internal/rancher/provisioning/v1/cluster.go rename to api/rancher/provisioning/v1/cluster.go diff --git a/internal/rancher/provisioning/v1/doc.go b/api/rancher/provisioning/v1/doc.go similarity index 100% rename from internal/rancher/provisioning/v1/doc.go rename to api/rancher/provisioning/v1/doc.go diff --git a/internal/rancher/provisioning/v1/groupversion_info.go b/api/rancher/provisioning/v1/groupversion_info.go similarity index 100% rename from internal/rancher/provisioning/v1/groupversion_info.go rename to api/rancher/provisioning/v1/groupversion_info.go diff --git a/internal/rancher/provisioning/v1/rke.go b/api/rancher/provisioning/v1/rke.go similarity index 100% rename from internal/rancher/provisioning/v1/rke.go rename to api/rancher/provisioning/v1/rke.go diff --git a/internal/rancher/provisioning/v1/zz_generated.deepcopy.go b/api/rancher/provisioning/v1/zz_generated.deepcopy.go similarity index 100% rename from internal/rancher/provisioning/v1/zz_generated.deepcopy.go rename to api/rancher/provisioning/v1/zz_generated.deepcopy.go diff --git a/docs/adr/0009-use-structured-proxy-types.md b/docs/adr/0009-use-structured-proxy-types.md index 518bc87a..b987500c 100644 --- a/docs/adr/0009-use-structured-proxy-types.md +++ b/docs/adr/0009-use-structured-proxy-types.md @@ -21,7 +21,7 @@ As described in `Rancher` integration strategy [ADR](./0005-rancher-integration- ## Decision -The `rancher-turtles` operator will be using `kubebuilder` [annotations](https://kubebuilder.io/reference/markers) on specified for the `Rancher` proxy types located under the `./internal/rancher` directory, to generate deep copy definitions and therefore allow specified resources to match the `Object` [interface](https://github.com/kubernetes-sigs/controller-runtime/blob/main/pkg/client/object.go#L45) provided by the controller-runtime. +The `rancher-turtles` operator will be using `kubebuilder` [annotations](https://kubebuilder.io/reference/markers) on specified for the `Rancher` proxy types located under the `./api/rancher` directory, to generate deep copy definitions and therefore allow specified resources to match the `Object` [interface](https://github.com/kubernetes-sigs/controller-runtime/blob/main/pkg/client/object.go#L45) provided by the controller-runtime. This will allow us to: diff --git a/internal/controllers/helpers.go b/internal/controllers/helpers.go index ba81fbff..edc90081 100644 --- a/internal/controllers/helpers.go +++ b/internal/controllers/helpers.go @@ -41,7 +41,7 @@ import ( clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" utilyaml "sigs.k8s.io/cluster-api/util/yaml" - managementv3 "github.com/rancher/turtles/internal/rancher/management/v3" + managementv3 "github.com/rancher/turtles/api/rancher/management/v3" "github.com/rancher/turtles/util" ) diff --git a/internal/controllers/import_controller.go b/internal/controllers/import_controller.go index eff3203d..376e7983 100644 --- a/internal/controllers/import_controller.go +++ b/internal/controllers/import_controller.go @@ -44,9 +44,9 @@ import ( "sigs.k8s.io/cluster-api/util/conditions" "sigs.k8s.io/cluster-api/util/predicates" + managementv3 "github.com/rancher/turtles/api/rancher/management/v3" + provisioningv1 "github.com/rancher/turtles/api/rancher/provisioning/v1" "github.com/rancher/turtles/feature" - managementv3 "github.com/rancher/turtles/internal/rancher/management/v3" - provisioningv1 "github.com/rancher/turtles/internal/rancher/provisioning/v1" "github.com/rancher/turtles/util" turtlesannotations "github.com/rancher/turtles/util/annotations" turtlesnaming "github.com/rancher/turtles/util/naming" diff --git a/internal/controllers/import_controller_test.go b/internal/controllers/import_controller_test.go index 2223639a..16feb7d8 100644 --- a/internal/controllers/import_controller_test.go +++ b/internal/controllers/import_controller_test.go @@ -25,9 +25,9 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + managementv3 "github.com/rancher/turtles/api/rancher/management/v3" + provisioningv1 "github.com/rancher/turtles/api/rancher/provisioning/v1" "github.com/rancher/turtles/internal/controllers/testdata" - managementv3 "github.com/rancher/turtles/internal/rancher/management/v3" - provisioningv1 "github.com/rancher/turtles/internal/rancher/provisioning/v1" "github.com/rancher/turtles/internal/test" turtlesnaming "github.com/rancher/turtles/util/naming" corev1 "k8s.io/api/core/v1" diff --git a/internal/controllers/import_controller_v3.go b/internal/controllers/import_controller_v3.go index bebe98fc..c186fcd7 100644 --- a/internal/controllers/import_controller_v3.go +++ b/internal/controllers/import_controller_v3.go @@ -44,9 +44,9 @@ import ( "sigs.k8s.io/cluster-api/util/conditions" "sigs.k8s.io/cluster-api/util/predicates" + managementv3 "github.com/rancher/turtles/api/rancher/management/v3" + provisioningv1 "github.com/rancher/turtles/api/rancher/provisioning/v1" "github.com/rancher/turtles/feature" - managementv3 "github.com/rancher/turtles/internal/rancher/management/v3" - provisioningv1 "github.com/rancher/turtles/internal/rancher/provisioning/v1" "github.com/rancher/turtles/util" turtlesannotations "github.com/rancher/turtles/util/annotations" turtlesnaming "github.com/rancher/turtles/util/naming" diff --git a/internal/controllers/import_controller_v3_test.go b/internal/controllers/import_controller_v3_test.go index ceacf296..d20ced91 100644 --- a/internal/controllers/import_controller_v3_test.go +++ b/internal/controllers/import_controller_v3_test.go @@ -25,9 +25,9 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" + managementv3 "github.com/rancher/turtles/api/rancher/management/v3" + provisioningv1 "github.com/rancher/turtles/api/rancher/provisioning/v1" "github.com/rancher/turtles/internal/controllers/testdata" - managementv3 "github.com/rancher/turtles/internal/rancher/management/v3" - provisioningv1 "github.com/rancher/turtles/internal/rancher/provisioning/v1" "github.com/rancher/turtles/internal/test" turtlesnaming "github.com/rancher/turtles/util/naming" corev1 "k8s.io/api/core/v1" diff --git a/internal/controllers/patch_kcfg_controller.go b/internal/controllers/patch_kcfg_controller.go index ac6b545d..572e2dc5 100644 --- a/internal/controllers/patch_kcfg_controller.go +++ b/internal/controllers/patch_kcfg_controller.go @@ -35,7 +35,7 @@ import ( "sigs.k8s.io/cluster-api/controllers/external" "sigs.k8s.io/cluster-api/util/predicates" - provisioningv1 "github.com/rancher/turtles/internal/rancher/provisioning/v1" + provisioningv1 "github.com/rancher/turtles/api/rancher/provisioning/v1" turtlespredicates "github.com/rancher/turtles/util/predicates" ) diff --git a/internal/controllers/patch_kcfg_controller_test.go b/internal/controllers/patch_kcfg_controller_test.go index f1f20bf0..481d86d3 100644 --- a/internal/controllers/patch_kcfg_controller_test.go +++ b/internal/controllers/patch_kcfg_controller_test.go @@ -29,7 +29,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/reconcile" - provisioningv1 "github.com/rancher/turtles/internal/rancher/provisioning/v1" + provisioningv1 "github.com/rancher/turtles/api/rancher/provisioning/v1" "github.com/rancher/turtles/internal/test" ) diff --git a/internal/controllers/suite_test.go b/internal/controllers/suite_test.go index fded6f00..9c3b6ad4 100644 --- a/internal/controllers/suite_test.go +++ b/internal/controllers/suite_test.go @@ -28,9 +28,9 @@ import ( "k8s.io/client-go/kubernetes/scheme" ctrl "sigs.k8s.io/controller-runtime" + managementv3 "github.com/rancher/turtles/api/rancher/management/v3" + provisioningv1 "github.com/rancher/turtles/api/rancher/provisioning/v1" turtlesv1 "github.com/rancher/turtles/api/v1alpha1" - managementv3 "github.com/rancher/turtles/internal/rancher/management/v3" - provisioningv1 "github.com/rancher/turtles/internal/rancher/provisioning/v1" operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" diff --git a/main.go b/main.go index 7748ddb4..669b1263 100644 --- a/main.go +++ b/main.go @@ -46,11 +46,11 @@ import ( operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" + managementv3 "github.com/rancher/turtles/api/rancher/management/v3" + provisioningv1 "github.com/rancher/turtles/api/rancher/provisioning/v1" turtlesv1 "github.com/rancher/turtles/api/v1alpha1" "github.com/rancher/turtles/feature" "github.com/rancher/turtles/internal/controllers" - managementv3 "github.com/rancher/turtles/internal/rancher/management/v3" - provisioningv1 "github.com/rancher/turtles/internal/rancher/provisioning/v1" ) const maxDuration time.Duration = 1<<63 - 1 diff --git a/test/e2e/helpers.go b/test/e2e/helpers.go index 39223800..3773a1d0 100644 --- a/test/e2e/helpers.go +++ b/test/e2e/helpers.go @@ -39,8 +39,8 @@ import ( "sigs.k8s.io/cluster-api/util" "sigs.k8s.io/yaml" - managementv3 "github.com/rancher/turtles/internal/rancher/management/v3" - provisioningv1 "github.com/rancher/turtles/internal/rancher/provisioning/v1" + managementv3 "github.com/rancher/turtles/api/rancher/management/v3" + provisioningv1 "github.com/rancher/turtles/api/rancher/provisioning/v1" turtlesframework "github.com/rancher/turtles/test/framework" networkingv1 "k8s.io/api/networking/v1" ) diff --git a/test/e2e/specs/import_gitops.go b/test/e2e/specs/import_gitops.go index 47083a8b..e279d5ce 100644 --- a/test/e2e/specs/import_gitops.go +++ b/test/e2e/specs/import_gitops.go @@ -39,7 +39,7 @@ import ( "sigs.k8s.io/cluster-api/test/framework/clusterctl" "sigs.k8s.io/controller-runtime/pkg/envtest/komega" - provisioningv1 "github.com/rancher/turtles/internal/rancher/provisioning/v1" + provisioningv1 "github.com/rancher/turtles/api/rancher/provisioning/v1" "github.com/rancher/turtles/test/e2e" turtlesframework "github.com/rancher/turtles/test/framework" "github.com/rancher/turtles/test/testenv" diff --git a/test/e2e/specs/import_gitops_mgmtv3.go b/test/e2e/specs/import_gitops_mgmtv3.go index 0b7b4f3b..e25f2877 100644 --- a/test/e2e/specs/import_gitops_mgmtv3.go +++ b/test/e2e/specs/import_gitops_mgmtv3.go @@ -40,7 +40,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/envtest/komega" - managementv3 "github.com/rancher/turtles/internal/rancher/management/v3" + managementv3 "github.com/rancher/turtles/api/rancher/management/v3" "github.com/rancher/turtles/test/e2e" turtlesframework "github.com/rancher/turtles/test/framework" "github.com/rancher/turtles/test/testenv" diff --git a/test/e2e/specs/migrate_gitops_provv1_mgmtv3.go b/test/e2e/specs/migrate_gitops_provv1_mgmtv3.go index 3afa83e7..b4457a9e 100644 --- a/test/e2e/specs/migrate_gitops_provv1_mgmtv3.go +++ b/test/e2e/specs/migrate_gitops_provv1_mgmtv3.go @@ -42,8 +42,8 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/envtest/komega" - managementv3 "github.com/rancher/turtles/internal/rancher/management/v3" - provisioningv1 "github.com/rancher/turtles/internal/rancher/provisioning/v1" + managementv3 "github.com/rancher/turtles/api/rancher/management/v3" + provisioningv1 "github.com/rancher/turtles/api/rancher/provisioning/v1" "github.com/rancher/turtles/test/e2e" turtlesframework "github.com/rancher/turtles/test/framework" "github.com/rancher/turtles/test/testenv" diff --git a/test/e2e/suites/update-labels/update_labels_test.go b/test/e2e/suites/update-labels/update_labels_test.go index 72de3d40..d66fde17 100644 --- a/test/e2e/suites/update-labels/update_labels_test.go +++ b/test/e2e/suites/update-labels/update_labels_test.go @@ -32,7 +32,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/envtest/komega" - provisioningv1 "github.com/rancher/turtles/internal/rancher/provisioning/v1" + provisioningv1 "github.com/rancher/turtles/api/rancher/provisioning/v1" "github.com/rancher/turtles/test/e2e" turtlesframework "github.com/rancher/turtles/test/framework" "github.com/rancher/turtles/test/testenv" diff --git a/test/e2e/suites/v2prov/v2prov_test.go b/test/e2e/suites/v2prov/v2prov_test.go index 048ec333..a5631efe 100644 --- a/test/e2e/suites/v2prov/v2prov_test.go +++ b/test/e2e/suites/v2prov/v2prov_test.go @@ -32,7 +32,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/envtest/komega" - provisioningv1 "github.com/rancher/turtles/internal/rancher/provisioning/v1" + provisioningv1 "github.com/rancher/turtles/api/rancher/provisioning/v1" "github.com/rancher/turtles/test/e2e" turtlesframework "github.com/rancher/turtles/test/framework" "github.com/rancher/turtles/test/testenv" diff --git a/util/predicates/suite_test.go b/util/predicates/suite_test.go index 5fbdd7a9..470162ac 100644 --- a/util/predicates/suite_test.go +++ b/util/predicates/suite_test.go @@ -28,9 +28,9 @@ import ( "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" + managementv3 "github.com/rancher/turtles/api/rancher/management/v3" + provisioningv1 "github.com/rancher/turtles/api/rancher/provisioning/v1" turtlesv1 "github.com/rancher/turtles/api/v1alpha1" - managementv3 "github.com/rancher/turtles/internal/rancher/management/v3" - provisioningv1 "github.com/rancher/turtles/internal/rancher/provisioning/v1" operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" diff --git a/util/predicates/v2prov_predicates.go b/util/predicates/v2prov_predicates.go index 0c217a1a..d50a60d3 100644 --- a/util/predicates/v2prov_predicates.go +++ b/util/predicates/v2prov_predicates.go @@ -24,7 +24,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/predicate" - provisioningv1 "github.com/rancher/turtles/internal/rancher/provisioning/v1" + provisioningv1 "github.com/rancher/turtles/api/rancher/provisioning/v1" ) // V2ProvClusterOwned returns a predicate that checks for a v2prov cluster owner reference. From 70551ebb72d2aacd33e35325f0b50e477ae73e0a Mon Sep 17 00:00:00 2001 From: Danil-Grigorev Date: Thu, 29 Aug 2024 09:05:59 +0200 Subject: [PATCH 2/3] Add rancher setting under proxy types Signed-off-by: Danil-Grigorev --- Makefile | 2 +- api/rancher/management/v3/setting.go | 44 ++++++++++++++ .../management/v3/zz_generated.deepcopy.go | 57 +++++++++++++++++++ 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 api/rancher/management/v3/setting.go diff --git a/Makefile b/Makefile index 68a95597..5c0ecfc3 100644 --- a/Makefile +++ b/Makefile @@ -233,7 +233,7 @@ generate-manifests-external: vendor controller-gen ## Generate ClusterRole and C .PHONY: generate-manifests-api generate-manifests-api: controller-gen ## Generate ClusterRole and CustomResourceDefinition objects. - $(CONTROLLER_GEN) rbac:roleName=manager-role crd paths="./api/..." \ + $(CONTROLLER_GEN) rbac:roleName=manager-role crd paths="./api/v1alpha1/..." \ output:crd:artifacts:config=./config/crd/bases \ output:rbac:dir=./config/rbac \ diff --git a/api/rancher/management/v3/setting.go b/api/rancher/management/v3/setting.go new file mode 100644 index 00000000..bae7485a --- /dev/null +++ b/api/rancher/management/v3/setting.go @@ -0,0 +1,44 @@ +/* +Copyright © 2023 - 2024 SUSE LLC + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package v3 + +import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + +// Setting is the struct representing a Rancher Setting. +// +kubebuilder:object:root=true +type Setting struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Value string `json:"value"` + Default string `json:"default,omitempty"` + Customized bool `json:"customized,omitempty"` + Source string `json:"source"` +} + +// SettingList contains a list of Settings. +// +kubebuilder:object:root=true +type SettingList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + + Items []Setting `json:"items"` +} + +func init() { + SchemeBuilder.Register(&Setting{}, &SettingList{}) +} diff --git a/api/rancher/management/v3/zz_generated.deepcopy.go b/api/rancher/management/v3/zz_generated.deepcopy.go index 6ed290f7..b3d28e91 100644 --- a/api/rancher/management/v3/zz_generated.deepcopy.go +++ b/api/rancher/management/v3/zz_generated.deepcopy.go @@ -209,3 +209,60 @@ func (in *ClusterStatus) DeepCopy() *ClusterStatus { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Setting) DeepCopyInto(out *Setting) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Setting. +func (in *Setting) DeepCopy() *Setting { + if in == nil { + return nil + } + out := new(Setting) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *Setting) 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 *SettingList) DeepCopyInto(out *SettingList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]Setting, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SettingList. +func (in *SettingList) DeepCopy() *SettingList { + if in == nil { + return nil + } + out := new(SettingList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *SettingList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} From c8ab82c7be233b5c7ce83eace580f3161e563c71 Mon Sep 17 00:00:00 2001 From: Danil-Grigorev Date: Thu, 29 Aug 2024 09:12:58 +0200 Subject: [PATCH 3/3] Remove usage of unstructured within etcdrestore package Signed-off-by: Danil-Grigorev --- exp/etcdrestore/webhooks/rke2config.go | 28 ++++++-------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/exp/etcdrestore/webhooks/rke2config.go b/exp/etcdrestore/webhooks/rke2config.go index 8d5b1860..ccbd79b8 100644 --- a/exp/etcdrestore/webhooks/rke2config.go +++ b/exp/etcdrestore/webhooks/rke2config.go @@ -23,13 +23,12 @@ import ( "strings" bootstrapv1 "github.com/rancher/cluster-api-provider-rke2/bootstrap/api/v1beta1" + managementv3 "github.com/rancher/turtles/api/rancher/management/v3" corev1 "k8s.io/api/core/v1" rbacv1 "k8s.io/api/rbac/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/tools/clientcmd" clientcmdapi "k8s.io/client-go/tools/clientcmd/api" "k8s.io/client-go/util/retry" @@ -89,43 +88,28 @@ func (r *RKE2ConfigWebhook) Default(ctx context.Context, obj runtime.Object) err logger.Info("Service account secret is populated") - serverUrlSetting := &unstructured.Unstructured{} - serverUrlSetting.SetGroupVersionKind(schema.GroupVersionKind{ - Group: "management.cattle.io", - Kind: "Setting", - Version: "v3", - }) + serverUrlSetting := &managementv3.Setting{} if err := r.Get(context.Background(), client.ObjectKey{ Name: "server-url", }, serverUrlSetting); err != nil { return apierrors.NewBadRequest(fmt.Sprintf("failed to get server url setting: %s", err)) } - serverUrl, ok := serverUrlSetting.Object["value"].(string) - if !ok { - return apierrors.NewBadRequest(fmt.Sprintf("failed to get server url setting: %s", err)) - } + + serverUrl := serverUrlSetting.Value if serverUrl == "" { return apierrors.NewBadRequest("server url setting is empty") } - caSetting := &unstructured.Unstructured{} - caSetting.SetGroupVersionKind(schema.GroupVersionKind{ - Group: "management.cattle.io", - Kind: "Setting", - Version: "v3", - }) + caSetting := &managementv3.Setting{} if err := r.Get(context.Background(), client.ObjectKey{ Name: "cacerts", }, caSetting); err != nil { return apierrors.NewBadRequest(fmt.Sprintf("failed to get ca setting: %s", err)) } - pem, ok := caSetting.Object["value"].(string) - if !ok { - return apierrors.NewBadRequest(fmt.Sprintf("failed to get ca setting: %s", err)) - } + pem := caSetting.Value if err := r.createConnectInfoJson(ctx, rke2Config, planSecretName, serverUrl, pem, serviceAccountToken); err != nil { return apierrors.NewBadRequest(fmt.Sprintf("failed to create connect info json: %s", err))