Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 ETCD backup/restore: use structured setting #698

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,14 @@ 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

.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 \

Expand All @@ -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
Expand Down
File renamed without changes.
44 changes: 44 additions & 0 deletions api/rancher/management/v3/setting.go
Original file line number Diff line number Diff line change
@@ -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{})
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/adr/0009-use-structured-proxy-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
28 changes: 6 additions & 22 deletions exp/etcdrestore/webhooks/rke2config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/import_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/import_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/import_controller_v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/import_controller_v3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/patch_kcfg_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/patch_kcfg_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/import_gitops.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/specs/import_gitops_mgmtv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/specs/migrate_gitops_provv1_mgmtv3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/suites/update-labels/update_labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/suites/v2prov/v2prov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions util/predicates/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion util/predicates/v2prov_predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading