From 48784c78d4291858d046b8fe7f15b138629e3fa3 Mon Sep 17 00:00:00 2001 From: Arkadiusz Galwas Date: Tue, 12 Sep 2023 07:33:07 +0200 Subject: [PATCH 1/7] CRD renamed --- ...ster_types.go => gardenercluster_types.go} | 26 +++++----- api/v1/zz_generated.deepcopy.go | 38 +++++++------- cmd/main.go | 2 +- ...ry.kyma-project.io_clusterinventories.yaml | 49 ------------------- ...terinventory.kyma-project.io_clusters.yaml | 16 +++--- .../crd/patches/cainjection_in_clusters.yaml | 2 +- config/crd/patches/webhook_in_clusters.yaml | 2 +- internal/controller/cluster_controller.go | 6 +-- 8 files changed, 46 insertions(+), 95 deletions(-) rename api/v1/{cluster_types.go => gardenercluster_types.go} (66%) delete mode 100644 config/crd/bases/clusterinventory.kyma-project.io_clusterinventories.yaml diff --git a/api/v1/cluster_types.go b/api/v1/gardenercluster_types.go similarity index 66% rename from api/v1/cluster_types.go rename to api/v1/gardenercluster_types.go index 9f52d671..0efd210e 100644 --- a/api/v1/cluster_types.go +++ b/api/v1/gardenercluster_types.go @@ -23,17 +23,17 @@ import ( // EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! // NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. -// ClusterSpec defines the desired state of Cluster -type ClusterSpec struct { +// GardenerClusterSpec defines the desired state of GardenerCluster +type GardenerClusterSpec struct { // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster // Important: Run "make" to regenerate code after modifying this file - // Foo is an example field of Cluster. Edit cluster_types.go to remove/update + // Foo is an example field of GardenerCluster. Edit gardenercluster_types.go to remove/update Foo string `json:"foo,omitempty"` } -// ClusterStatus defines the observed state of Cluster -type ClusterStatus struct { +// GardenerClusterStatus defines the observed state of GardenerCluster +type GardenerClusterStatus struct { // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster // Important: Run "make" to regenerate code after modifying this file } @@ -41,24 +41,24 @@ type ClusterStatus struct { //+kubebuilder:object:root=true //+kubebuilder:subresource:status -// Cluster is the Schema for the clusters API -type Cluster struct { +// GardenerCluster is the Schema for the clusters API +type GardenerCluster struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec ClusterSpec `json:"spec,omitempty"` - Status ClusterStatus `json:"status,omitempty"` + Spec GardenerClusterSpec `json:"spec,omitempty"` + Status GardenerClusterStatus `json:"status,omitempty"` } //+kubebuilder:object:root=true -// ClusterList contains a list of Cluster -type ClusterList struct { +// GardenerClusterList contains a list of GardenerCluster +type GardenerClusterList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty"` - Items []Cluster `json:"items"` + Items []GardenerCluster `json:"items"` } func init() { - SchemeBuilder.Register(&Cluster{}, &ClusterList{}) + SchemeBuilder.Register(&GardenerCluster{}, &GardenerClusterList{}) } diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 34293ffe..859b4959 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -26,7 +26,7 @@ import ( ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Cluster) DeepCopyInto(out *Cluster) { +func (in *GardenerCluster) DeepCopyInto(out *GardenerCluster) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) @@ -34,18 +34,18 @@ func (in *Cluster) DeepCopyInto(out *Cluster) { out.Status = in.Status } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Cluster. -func (in *Cluster) DeepCopy() *Cluster { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GardenerCluster. +func (in *GardenerCluster) DeepCopy() *GardenerCluster { if in == nil { return nil } - out := new(Cluster) + out := new(GardenerCluster) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *Cluster) DeepCopyObject() runtime.Object { +func (in *GardenerCluster) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -53,31 +53,31 @@ func (in *Cluster) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ClusterList) DeepCopyInto(out *ClusterList) { +func (in *GardenerClusterList) DeepCopyInto(out *GardenerClusterList) { *out = *in out.TypeMeta = in.TypeMeta in.ListMeta.DeepCopyInto(&out.ListMeta) if in.Items != nil { in, out := &in.Items, &out.Items - *out = make([]Cluster, len(*in)) + *out = make([]GardenerCluster, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterList. -func (in *ClusterList) DeepCopy() *ClusterList { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GardenerClusterList. +func (in *GardenerClusterList) DeepCopy() *GardenerClusterList { if in == nil { return nil } - out := new(ClusterList) + out := new(GardenerClusterList) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *ClusterList) DeepCopyObject() runtime.Object { +func (in *GardenerClusterList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -85,31 +85,31 @@ func (in *ClusterList) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ClusterSpec) DeepCopyInto(out *ClusterSpec) { +func (in *GardenerClusterSpec) DeepCopyInto(out *GardenerClusterSpec) { *out = *in } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterSpec. -func (in *ClusterSpec) DeepCopy() *ClusterSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GardenerClusterSpec. +func (in *GardenerClusterSpec) DeepCopy() *GardenerClusterSpec { if in == nil { return nil } - out := new(ClusterSpec) + out := new(GardenerClusterSpec) in.DeepCopyInto(out) return out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ClusterStatus) DeepCopyInto(out *ClusterStatus) { +func (in *GardenerClusterStatus) DeepCopyInto(out *GardenerClusterStatus) { *out = *in } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterStatus. -func (in *ClusterStatus) DeepCopy() *ClusterStatus { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GardenerClusterStatus. +func (in *GardenerClusterStatus) DeepCopy() *GardenerClusterStatus { if in == nil { return nil } - out := new(ClusterStatus) + out := new(GardenerClusterStatus) in.DeepCopyInto(out) return out } diff --git a/cmd/main.go b/cmd/main.go index 03881545..97d959c3 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -93,7 +93,7 @@ func main() { Client: mgr.GetClient(), Scheme: mgr.GetScheme(), }).SetupWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create controller", "controller", "Cluster") + setupLog.Error(err, "unable to create controller", "controller", "GardenerCluster") os.Exit(1) } //+kubebuilder:scaffold:builder diff --git a/config/crd/bases/clusterinventory.kyma-project.io_clusterinventories.yaml b/config/crd/bases/clusterinventory.kyma-project.io_clusterinventories.yaml deleted file mode 100644 index 86a0c7c0..00000000 --- a/config/crd/bases/clusterinventory.kyma-project.io_clusterinventories.yaml +++ /dev/null @@ -1,49 +0,0 @@ ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.12.0 - name: clusterinventories.clusterinventory.kyma-project.io -spec: - group: clusterinventory.kyma-project.io - names: - kind: ClusterInventory - listKind: ClusterInventoryList - plural: clusterinventories - singular: clusterinventory - scope: Namespaced - versions: - - name: v1 - schema: - openAPIV3Schema: - description: ClusterInventory is the Schema for the clusterinventories 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: ClusterInventorySpec defines the desired state of ClusterInventory - properties: - foo: - description: Foo is an example field of ClusterInventory. Edit clusterinventory_types.go - to remove/update - type: string - type: object - status: - description: ClusterInventoryStatus defines the observed state of ClusterInventory - type: object - type: object - served: true - storage: true - subresources: - status: {} diff --git a/config/crd/bases/clusterinventory.kyma-project.io_clusters.yaml b/config/crd/bases/clusterinventory.kyma-project.io_clusters.yaml index bb577ff5..a992e8c9 100644 --- a/config/crd/bases/clusterinventory.kyma-project.io_clusters.yaml +++ b/config/crd/bases/clusterinventory.kyma-project.io_clusters.yaml @@ -4,20 +4,20 @@ kind: CustomResourceDefinition metadata: annotations: controller-gen.kubebuilder.io/version: v0.12.0 - name: clusters.clusterinventory.kyma-project.io + name: gardenerclusters.clusterinventory.kyma-project.io spec: group: clusterinventory.kyma-project.io names: - kind: Cluster - listKind: ClusterList - plural: clusters - singular: cluster + kind: GardenerCluster + listKind: GardenerClusterList + plural: gardenerclusters + singular: gardenercluster scope: Namespaced versions: - name: v1 schema: openAPIV3Schema: - description: Cluster is the Schema for the clusters API + description: Gardener Cluster is the Schema for the gardenerclusters API properties: apiVersion: description: 'APIVersion defines the versioned schema of this representation @@ -32,7 +32,7 @@ spec: metadata: type: object spec: - description: ClusterSpec defines the desired state of Cluster + description: GardenerClusterSpec defines the desired state of GardenerCluster properties: foo: description: Foo is an example field of Cluster. Edit cluster_types.go @@ -40,7 +40,7 @@ spec: type: string type: object status: - description: ClusterStatus defines the observed state of Cluster + description: GardenerClusterStatus defines the observed state of Cluster type: object type: object served: true diff --git a/config/crd/patches/cainjection_in_clusters.yaml b/config/crd/patches/cainjection_in_clusters.yaml index 3979d4a5..b4765ccb 100644 --- a/config/crd/patches/cainjection_in_clusters.yaml +++ b/config/crd/patches/cainjection_in_clusters.yaml @@ -4,4 +4,4 @@ kind: CustomResourceDefinition metadata: annotations: cert-manager.io/inject-ca-from: CERTIFICATE_NAMESPACE/CERTIFICATE_NAME - name: clusters.clusterinventory.kyma-project.io + name: gardenerclusters.clusterinventory.kyma-project.io diff --git a/config/crd/patches/webhook_in_clusters.yaml b/config/crd/patches/webhook_in_clusters.yaml index 09d57b56..eea6628f 100644 --- a/config/crd/patches/webhook_in_clusters.yaml +++ b/config/crd/patches/webhook_in_clusters.yaml @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: - name: clusters.clusterinventory.kyma-project.io + name: gardenerclusters.clusterinventory.kyma-project.io spec: conversion: strategy: Webhook diff --git a/internal/controller/cluster_controller.go b/internal/controller/cluster_controller.go index b1704eb8..1f8c0c67 100644 --- a/internal/controller/cluster_controller.go +++ b/internal/controller/cluster_controller.go @@ -27,7 +27,7 @@ import ( clusterinventoryv1 "github.com/kyma-project/cluster-inventory/api/v1" ) -// ClusterReconciler reconciles a Cluster object +// ClusterReconciler reconciles a GardenerCluster object type ClusterReconciler struct { client.Client Scheme *runtime.Scheme @@ -40,7 +40,7 @@ type ClusterReconciler struct { // Reconcile is part of the main kubernetes reconciliation loop which aims to // move the current state of the cluster closer to the desired state. // TODO(user): Modify the Reconcile function to compare the state specified by -// the Cluster object against the actual cluster state, and then +// the GardenerCluster object against the actual cluster state, and then // perform operations to make the cluster state reflect the state specified by // the user. // @@ -57,6 +57,6 @@ func (r *ClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct // SetupWithManager sets up the controller with the Manager. func (r *ClusterReconciler) SetupWithManager(mgr ctrl.Manager) error { return ctrl.NewControllerManagedBy(mgr). - For(&clusterinventoryv1.Cluster{}). + For(&clusterinventoryv1.GardenerCluster{}). Complete(r) } From 1b12bccb183da84169baa674a408803eb70c1ca6 Mon Sep 17 00:00:00 2001 From: Arkadiusz Galwas Date: Tue, 12 Sep 2023 12:56:03 +0200 Subject: [PATCH 2/7] Fields added --- api/v1/gardenercluster_types.go | 54 +++++++++++------ api/v1/zz_generated.deepcopy.go | 58 ++++++++++++++++++- ...terinventory.kyma-project.io_clusters.yaml | 49 ---------------- config/rbac/cluster_editor_role.yaml | 4 +- config/rbac/cluster_viewer_role.yaml | 4 +- .../samples/clusterinventory_v1_cluster.yaml | 12 ---- .../clusterinventory_v1_gardenercluster.yaml | 23 ++++++++ config/samples/kustomization.yaml | 2 +- 8 files changed, 122 insertions(+), 84 deletions(-) delete mode 100644 config/crd/bases/clusterinventory.kyma-project.io_clusters.yaml delete mode 100644 config/samples/clusterinventory_v1_cluster.yaml create mode 100644 config/samples/clusterinventory_v1_gardenercluster.yaml diff --git a/api/v1/gardenercluster_types.go b/api/v1/gardenercluster_types.go index 0efd210e..59e80667 100644 --- a/api/v1/gardenercluster_types.go +++ b/api/v1/gardenercluster_types.go @@ -20,23 +20,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN! -// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized. - -// GardenerClusterSpec defines the desired state of GardenerCluster -type GardenerClusterSpec struct { - // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster - // Important: Run "make" to regenerate code after modifying this file - - // Foo is an example field of GardenerCluster. Edit gardenercluster_types.go to remove/update - Foo string `json:"foo,omitempty"` -} - -// GardenerClusterStatus defines the observed state of GardenerCluster -type GardenerClusterStatus struct { - // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster - // Important: Run "make" to regenerate code after modifying this file -} +type State string //+kubebuilder:object:root=true //+kubebuilder:subresource:status @@ -59,6 +43,42 @@ type GardenerClusterList struct { Items []GardenerCluster `json:"items"` } +// GardenerClusterSpec defines the desired state of GardenerCluster +type GardenerClusterSpec struct { + Shoot Shoot `json:"shoot,omitempty"` + Kubeconfig Kubeconfig `json:"kubeconfig,omitempty"` +} + +// Shoot defines the desired state of the Gardener's shoot +type Shoot struct { + Name string `json:"name,omitempty"` +} + +// Kubeconfig defines the desired kubeconfig location +type Kubeconfig struct { + SecretKeyRef SecretKeyRef `json:"secretKeyRef,omitempty"` +} + +// SecretKeyRef defines the location, and structure of the secret containing kubeconfig +type SecretKeyRef struct { + Name string `json:"name,omitempty"` + Namespace string `json:"namespace,omitempty"` + Key string `json:"key,omitempty"` +} + +// GardenerClusterStatus defines the observed state of GardenerCluster +type GardenerClusterStatus struct { + // State signifies current state of Gardener Cluster. + // Value can be one of ("Ready", "Processing", "Error", "Deleting"). + State State `json:"state,omitempty"` + + // List of status conditions to indicate the status of a ServiceInstance. + // +optional + // +listType=map + // +listMapKey=type + Conditions []metav1.Condition `json:"conditions,omitempty"` +} + func init() { SchemeBuilder.Register(&GardenerCluster{}, &GardenerClusterList{}) } diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 859b4959..711d35ec 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -22,6 +22,7 @@ limitations under the License. package v1 import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -31,7 +32,7 @@ func (in *GardenerCluster) DeepCopyInto(out *GardenerCluster) { out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) out.Spec = in.Spec - out.Status = in.Status + in.Status.DeepCopyInto(&out.Status) } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GardenerCluster. @@ -87,6 +88,8 @@ func (in *GardenerClusterList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *GardenerClusterSpec) DeepCopyInto(out *GardenerClusterSpec) { *out = *in + out.Shoot = in.Shoot + out.Kubeconfig = in.Kubeconfig } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GardenerClusterSpec. @@ -102,6 +105,13 @@ func (in *GardenerClusterSpec) DeepCopy() *GardenerClusterSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *GardenerClusterStatus) DeepCopyInto(out *GardenerClusterStatus) { *out = *in + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make([]metav1.Condition, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GardenerClusterStatus. @@ -113,3 +123,49 @@ func (in *GardenerClusterStatus) DeepCopy() *GardenerClusterStatus { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Kubeconfig) DeepCopyInto(out *Kubeconfig) { + *out = *in + out.SecretKeyRef = in.SecretKeyRef +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Kubeconfig. +func (in *Kubeconfig) DeepCopy() *Kubeconfig { + if in == nil { + return nil + } + out := new(Kubeconfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SecretKeyRef) DeepCopyInto(out *SecretKeyRef) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SecretKeyRef. +func (in *SecretKeyRef) DeepCopy() *SecretKeyRef { + if in == nil { + return nil + } + out := new(SecretKeyRef) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Shoot) DeepCopyInto(out *Shoot) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Shoot. +func (in *Shoot) DeepCopy() *Shoot { + if in == nil { + return nil + } + out := new(Shoot) + in.DeepCopyInto(out) + return out +} diff --git a/config/crd/bases/clusterinventory.kyma-project.io_clusters.yaml b/config/crd/bases/clusterinventory.kyma-project.io_clusters.yaml deleted file mode 100644 index a992e8c9..00000000 --- a/config/crd/bases/clusterinventory.kyma-project.io_clusters.yaml +++ /dev/null @@ -1,49 +0,0 @@ ---- -apiVersion: apiextensions.k8s.io/v1 -kind: CustomResourceDefinition -metadata: - annotations: - controller-gen.kubebuilder.io/version: v0.12.0 - name: gardenerclusters.clusterinventory.kyma-project.io -spec: - group: clusterinventory.kyma-project.io - names: - kind: GardenerCluster - listKind: GardenerClusterList - plural: gardenerclusters - singular: gardenercluster - scope: Namespaced - versions: - - name: v1 - schema: - openAPIV3Schema: - description: Gardener Cluster is the Schema for the gardenerclusters 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: GardenerClusterSpec defines the desired state of GardenerCluster - properties: - foo: - description: Foo is an example field of Cluster. Edit cluster_types.go - to remove/update - type: string - type: object - status: - description: GardenerClusterStatus defines the observed state of Cluster - type: object - type: object - served: true - storage: true - subresources: - status: {} diff --git a/config/rbac/cluster_editor_role.yaml b/config/rbac/cluster_editor_role.yaml index 851c8e42..64e71328 100644 --- a/config/rbac/cluster_editor_role.yaml +++ b/config/rbac/cluster_editor_role.yaml @@ -14,7 +14,7 @@ rules: - apiGroups: - clusterinventory.kyma-project.io resources: - - clusters + - gardenerclusters verbs: - create - delete @@ -26,6 +26,6 @@ rules: - apiGroups: - clusterinventory.kyma-project.io resources: - - clusters/status + - gardenerclusters/status verbs: - get diff --git a/config/rbac/cluster_viewer_role.yaml b/config/rbac/cluster_viewer_role.yaml index 0d29f90f..7d858fe5 100644 --- a/config/rbac/cluster_viewer_role.yaml +++ b/config/rbac/cluster_viewer_role.yaml @@ -14,7 +14,7 @@ rules: - apiGroups: - clusterinventory.kyma-project.io resources: - - clusters + - gardenerclusters verbs: - get - list @@ -22,6 +22,6 @@ rules: - apiGroups: - clusterinventory.kyma-project.io resources: - - clusters/status + - gardenerclusters/status verbs: - get diff --git a/config/samples/clusterinventory_v1_cluster.yaml b/config/samples/clusterinventory_v1_cluster.yaml deleted file mode 100644 index 9f36d5b0..00000000 --- a/config/samples/clusterinventory_v1_cluster.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: clusterinventory.kyma-project.io/v1 -kind: Cluster -metadata: - labels: - app.kubernetes.io/name: cluster - app.kubernetes.io/instance: cluster-sample - app.kubernetes.io/part-of: cluster-inventory - app.kubernetes.io/managed-by: kustomize - app.kubernetes.io/created-by: cluster-inventory - name: cluster-sample -spec: - # TODO(user): Add fields here diff --git a/config/samples/clusterinventory_v1_gardenercluster.yaml b/config/samples/clusterinventory_v1_gardenercluster.yaml new file mode 100644 index 00000000..0c7f8462 --- /dev/null +++ b/config/samples/clusterinventory_v1_gardenercluster.yaml @@ -0,0 +1,23 @@ +apiVersion: clusterinventory.kyma-project.io/v1 +kind: GardenerCluster +metadata: + labels: + kyma-project.io/instance-id: instance-id + kyma-project.io/runtime-id: runtime-id + kyma-project.io/broker-plan-id: plan-id + kyma-project.io/broker-plan-name: plan-name + kyma-project.io/global-account-id: global-account-id + kyma-project.io/subaccount-id: subAccount-id + kyma-project.io/shoot-name: shoot-name + kyma-project.io/region: region + operator.kyma-project.io/kyma-name: kymaName + name: cluster-sample + namespace: default +spec: + shoot: + name: "my-shoot" + kubeconfig: + secretKeyRef: + name: "kubeconfig-secret-name" + namespace: "kubeconfig-secret-namespace" + key: "config" diff --git a/config/samples/kustomization.yaml b/config/samples/kustomization.yaml index 3d4a5e47..05f52708 100644 --- a/config/samples/kustomization.yaml +++ b/config/samples/kustomization.yaml @@ -1,4 +1,4 @@ ## Append samples of your project ## resources: -- clusterinventory_v1_cluster.yaml +- clusterinventory_v1_gardenercluster.yaml #+kubebuilder:scaffold:manifestskustomizesamples From 761dbf9ab4326a2ba9ade083ac37eaeba47f3268 Mon Sep 17 00:00:00 2001 From: Arkadiusz Galwas Date: Tue, 12 Sep 2023 17:57:02 +0200 Subject: [PATCH 3/7] Fields adjusted --- api/v1/gardenercluster_types.go | 31 ++++++++++--------- api/v1/zz_generated.deepcopy.go | 26 +++------------- .../clusterinventory_v1_gardenercluster.yaml | 6 ++-- 3 files changed, 23 insertions(+), 40 deletions(-) diff --git a/api/v1/gardenercluster_types.go b/api/v1/gardenercluster_types.go index 59e80667..443a99cb 100644 --- a/api/v1/gardenercluster_types.go +++ b/api/v1/gardenercluster_types.go @@ -20,8 +20,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -type State string - //+kubebuilder:object:root=true //+kubebuilder:subresource:status @@ -30,7 +28,7 @@ type GardenerCluster struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec GardenerClusterSpec `json:"spec,omitempty"` + Spec GardenerClusterSpec `json:"spec"` Status GardenerClusterStatus `json:"status,omitempty"` } @@ -45,27 +43,30 @@ type GardenerClusterList struct { // GardenerClusterSpec defines the desired state of GardenerCluster type GardenerClusterSpec struct { - Shoot Shoot `json:"shoot,omitempty"` - Kubeconfig Kubeconfig `json:"kubeconfig,omitempty"` -} - -// Shoot defines the desired state of the Gardener's shoot -type Shoot struct { - Name string `json:"name,omitempty"` + Kubeconfig Kubeconfig `json:"kubeconfig"` } // Kubeconfig defines the desired kubeconfig location type Kubeconfig struct { - SecretKeyRef SecretKeyRef `json:"secretKeyRef,omitempty"` + Secret Secret `json:"secret"` } // SecretKeyRef defines the location, and structure of the secret containing kubeconfig -type SecretKeyRef struct { - Name string `json:"name,omitempty"` - Namespace string `json:"namespace,omitempty"` - Key string `json:"key,omitempty"` +type Secret struct { + Name string `json:"name"` + Namespace string `json:"namespace"` + Key string `json:"key"` } +type State string + +const ( + ReadyState State = "Ready" + ProcessingState State = "Processing" + ErrorState State = "Error" + DeletingState State = "Deleting" +) + // GardenerClusterStatus defines the observed state of GardenerCluster type GardenerClusterStatus struct { // State signifies current state of Gardener Cluster. diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 711d35ec..5ef97f89 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -88,7 +88,6 @@ func (in *GardenerClusterList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *GardenerClusterSpec) DeepCopyInto(out *GardenerClusterSpec) { *out = *in - out.Shoot = in.Shoot out.Kubeconfig = in.Kubeconfig } @@ -127,7 +126,7 @@ func (in *GardenerClusterStatus) DeepCopy() *GardenerClusterStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Kubeconfig) DeepCopyInto(out *Kubeconfig) { *out = *in - out.SecretKeyRef = in.SecretKeyRef + out.Secret = in.Secret } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Kubeconfig. @@ -141,31 +140,16 @@ func (in *Kubeconfig) DeepCopy() *Kubeconfig { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *SecretKeyRef) DeepCopyInto(out *SecretKeyRef) { +func (in *Secret) DeepCopyInto(out *Secret) { *out = *in } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SecretKeyRef. -func (in *SecretKeyRef) DeepCopy() *SecretKeyRef { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Secret. +func (in *Secret) DeepCopy() *Secret { if in == nil { return nil } - out := new(SecretKeyRef) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Shoot) DeepCopyInto(out *Shoot) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Shoot. -func (in *Shoot) DeepCopy() *Shoot { - if in == nil { - return nil - } - out := new(Shoot) + out := new(Secret) in.DeepCopyInto(out) return out } diff --git a/config/samples/clusterinventory_v1_gardenercluster.yaml b/config/samples/clusterinventory_v1_gardenercluster.yaml index 0c7f8462..265e9eb1 100644 --- a/config/samples/clusterinventory_v1_gardenercluster.yaml +++ b/config/samples/clusterinventory_v1_gardenercluster.yaml @@ -11,13 +11,11 @@ metadata: kyma-project.io/shoot-name: shoot-name kyma-project.io/region: region operator.kyma-project.io/kyma-name: kymaName - name: cluster-sample + name: shoot-name namespace: default spec: - shoot: - name: "my-shoot" kubeconfig: - secretKeyRef: + secret: name: "kubeconfig-secret-name" namespace: "kubeconfig-secret-namespace" key: "config" From 589d9fa48674e4faf1ea7b96498cdb668eb2f60f Mon Sep 17 00:00:00 2001 From: Arkadiusz Galwas Date: Tue, 12 Sep 2023 18:05:11 +0200 Subject: [PATCH 4/7] CRD defined as cluster scoped --- PROJECT | 2 +- config/crd/kustomization.yaml | 2 +- config/manager/kustomization.yaml | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/PROJECT b/PROJECT index 68c06657..3145c6fa 100644 --- a/PROJECT +++ b/PROJECT @@ -10,7 +10,7 @@ repo: github.com/kyma-project/cluster-inventory resources: - api: crdVersion: v1 - namespaced: true + namespaced: false controller: true domain: kyma-project.io group: clusterinventory diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index 668d44b6..c197457e 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -2,7 +2,7 @@ # since it depends on service name and namespace that are out of this kustomize package. # It should be run by config/default resources: -- bases/clusterinventory.kyma-project.io_clusters.yaml +- bases/clusterinventory.kyma-project.io_gardenerclusters.yaml #+kubebuilder:scaffold:crdkustomizeresource patches: diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml index 5c5f0b84..ad13e96b 100644 --- a/config/manager/kustomization.yaml +++ b/config/manager/kustomization.yaml @@ -1,2 +1,8 @@ resources: - manager.yaml +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +images: +- name: controller + newName: controller + newTag: latest From ba224f3e610d9cbf188b74159d490c0e6f060cc1 Mon Sep 17 00:00:00 2001 From: Arkadiusz Galwas Date: Wed, 13 Sep 2023 13:18:17 +0200 Subject: [PATCH 5/7] Discussion results --- config/samples/clusterinventory_v1_gardenercluster.yaml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/config/samples/clusterinventory_v1_gardenercluster.yaml b/config/samples/clusterinventory_v1_gardenercluster.yaml index 265e9eb1..d9bde269 100644 --- a/config/samples/clusterinventory_v1_gardenercluster.yaml +++ b/config/samples/clusterinventory_v1_gardenercluster.yaml @@ -11,11 +11,13 @@ metadata: kyma-project.io/shoot-name: shoot-name kyma-project.io/region: region operator.kyma-project.io/kyma-name: kymaName - name: shoot-name - namespace: default + name: runtimeID + namespace: kcp-system spec: + shoot: + name: shoot-name kubeconfig: secret: name: "kubeconfig-secret-name" - namespace: "kubeconfig-secret-namespace" + namespace: kcp-system key: "config" From ab196ebdecc72f2fbc87b0322b2ede3f5f65f39a Mon Sep 17 00:00:00 2001 From: Arkadiusz Galwas Date: Wed, 13 Sep 2023 13:18:52 +0200 Subject: [PATCH 6/7] Update clusterinventory_v1_gardenercluster.yaml --- config/samples/clusterinventory_v1_gardenercluster.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/samples/clusterinventory_v1_gardenercluster.yaml b/config/samples/clusterinventory_v1_gardenercluster.yaml index d9bde269..71534f45 100644 --- a/config/samples/clusterinventory_v1_gardenercluster.yaml +++ b/config/samples/clusterinventory_v1_gardenercluster.yaml @@ -11,7 +11,7 @@ metadata: kyma-project.io/shoot-name: shoot-name kyma-project.io/region: region operator.kyma-project.io/kyma-name: kymaName - name: runtimeID + name: runtime-id namespace: kcp-system spec: shoot: From 726c03a48a43eaabf544b93c8ea9a831d7c6d279 Mon Sep 17 00:00:00 2001 From: Arkadiusz Galwas Date: Wed, 13 Sep 2023 13:19:24 +0200 Subject: [PATCH 7/7] Update clusterinventory_v1_gardenercluster.yaml --- config/samples/clusterinventory_v1_gardenercluster.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/samples/clusterinventory_v1_gardenercluster.yaml b/config/samples/clusterinventory_v1_gardenercluster.yaml index 71534f45..d571200b 100644 --- a/config/samples/clusterinventory_v1_gardenercluster.yaml +++ b/config/samples/clusterinventory_v1_gardenercluster.yaml @@ -18,6 +18,6 @@ spec: name: shoot-name kubeconfig: secret: - name: "kubeconfig-secret-name" + name: kubeconfig-runtime-id namespace: kcp-system key: "config"