diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index bfd75fd..ab36ffa 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -51,8 +51,8 @@ jobs: uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 with: registry: ${{ env.REGISTRY }} - username: ${{ secrets.WGE_DOCKER_IO_USER }} - password: ${{ secrets.WGE_DOCKER_IO_PASSWORD }} + username: ${{ secrets.DOCKER_IO_USER }} + password: ${{ secrets.DOCKER_IO_PASSWORD }} - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@dbef88086f6cef02e264edb7dbf63250c17cef6c # v5.5.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d3bfd9..8cacdfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,7 +31,7 @@ ### Bug Fixes * use CAPIClusterRef when looking for kubeconfig secret ([4191177](https://github.com/weaveworks/cluster-controller/commit/4191177a12f6139e3eab3566b02e8be916adafea)) -* use the NewGitopsClusterReconciler constructor ([a472d8c](https://github.com/weaveworks/cluster-controller/commit/a472d8c3d047691180d7fb6fc4710e3c79ec48e9)) +* use the NewGitOpsClusterReconciler constructor ([a472d8c](https://github.com/weaveworks/cluster-controller/commit/a472d8c3d047691180d7fb6fc4710e3c79ec48e9)) * wait for control plane for readiness ([7d9497f](https://github.com/weaveworks/cluster-controller/commit/7d9497f4eea5714bd3b8b207559d179a4e4598a2)) ## 1.0.0 (2022-04-21) diff --git a/Makefile b/Makefile index 15dc446..b82c01f 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ VERSION ?= 0.0.1 # Image URL to use all building/pushing image targets IMG ?= controller:latest # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. -ENVTEST_K8S_VERSION = 1.27 +ENVTEST_K8S_VERSION = 1.29 # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) diff --git a/PROJECT b/PROJECT index f0f5a5b..be6649c 100644 --- a/PROJECT +++ b/PROJECT @@ -2,7 +2,7 @@ domain: weave.works layout: - go.kubebuilder.io/v3 projectName: cluster-controller -repo: github.com/weaveworks/cluster-controller +repo: github.com/gitops-tools/cluster-controller resources: - api: crdVersion: v1 @@ -10,7 +10,7 @@ resources: controller: true domain: weave.works group: gitops - kind: GitopsCluster - path: github.com/weaveworks/cluster-controller/api/v1alpha1 + kind: GitOpsCluster + path: github.com/gitops-tools/cluster-controller/api/v1alpha1 version: v1alpha1 version: "3" diff --git a/README.md b/README.md index 80a4e76..2230bdb 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,33 @@ cluster-controller for Weave GitOps Enterprise. +This provides an in-cluster representation of clusters. + +A `GitOpsCluster` can reference an existing CAPI cluster. + +```yaml +apiVersion: gitops.weave.works/v1alpha1 +kind: GitOpsCluster +metadata: + name: dev + namespace: default +spec: + capiClusterRef: + name: dev +``` + +Alternatively, a `GitOpsCluster` can reference a secret containing a kube config +file. + +```yaml +apiVersion: gitops.weave.works/v1alpha1 +kind: GitOpsCluster +metadata: + name: dev + namespace: default +spec: + secretRef: + name: dev +``` + This code was originally written for Weave GitOps Enterprise. diff --git a/api/v1alpha1/gitopscluster_types.go b/api/v1alpha1/gitopscluster_types.go index 25159ab..4cf69bb 100644 --- a/api/v1alpha1/gitopscluster_types.go +++ b/api/v1alpha1/gitopscluster_types.go @@ -22,15 +22,15 @@ import ( "github.com/fluxcd/pkg/apis/meta" ) -// GitOpsClusterNoSecretFinalizerAnnotation if applied to a GitopsCluster +// GitOpsClusterNoSecretFinalizerAnnotation if applied to a GitOpsCluster // indicates that we should not wait for the secret to be removed before // allowing the cluster to be removed. const GitOpsClusterNoSecretFinalizerAnnotation = "clusters.gitops.weave.works/no-secret-finalizer" -// GitopsClusterSpec defines the desired state of GitopsCluster +// GitOpsClusterSpec defines the desired state of GitOpsCluster // +kubebuilder:validation:XValidation:rule="(has(self.secretRef) || has(self.capiClusterRef))",message="must provide a secretRef or capiClusterRef" // +kubebuilder:validation:XValidation:rule="!(has(self.secretRef) && has(self.capiClusterRef))",message="cannot provide both capiClusterRef and secretRef" -type GitopsClusterSpec struct { +type GitOpsClusterSpec struct { // SecretRef specifies the Secret containing the kubeconfig for a cluster. // +optional SecretRef *meta.LocalObjectReference `json:"secretRef,omitempty"` @@ -39,20 +39,20 @@ type GitopsClusterSpec struct { CAPIClusterRef *meta.LocalObjectReference `json:"capiClusterRef,omitempty"` } -// GitopsClusterStatus defines the observed state of GitopsCluster -type GitopsClusterStatus struct { +// GitOpsClusterStatus defines the observed state of GitOpsCluster +type GitOpsClusterStatus struct { // Conditions holds the conditions for the Cluster. // +optional Conditions []metav1.Condition `json:"conditions,omitempty"` } // GetConditions returns the status conditions of the object. -func (in GitopsCluster) GetConditions() []metav1.Condition { +func (in GitOpsCluster) GetConditions() []metav1.Condition { return in.Status.Conditions } // SetConditions sets the status conditions on the object. -func (in *GitopsCluster) SetConditions(conditions []metav1.Condition) { +func (in *GitOpsCluster) SetConditions(conditions []metav1.Condition) { in.Status.Conditions = conditions } @@ -63,25 +63,25 @@ func (in *GitopsCluster) SetConditions(conditions []metav1.Condition) { // +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[?(@.type==\"Ready\")].message",description="" // +kubebuilder:printcolumn:name="ClusterConnectivity",type="string",JSONPath=".status.conditions[?(@.type==\"ClusterConnectivity\")].status",description="" -// GitopsCluster is the Schema for the gitopsclusters API +// GitOpsCluster is the Schema for the gitopsclusters API // +kubebuilder:validation:XValidation:rule="has(self.spec)",message="must confgure spec" -type GitopsCluster struct { +type GitOpsCluster struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty"` - Spec GitopsClusterSpec `json:"spec,omitempty"` - Status GitopsClusterStatus `json:"status,omitempty"` + Spec GitOpsClusterSpec `json:"spec,omitempty"` + Status GitOpsClusterStatus `json:"status,omitempty"` } // +kubebuilder:object:root=true -// GitopsClusterList contains a list of GitopsCluster -type GitopsClusterList struct { +// GitOpsClusterList contains a list of GitOpsCluster +type GitOpsClusterList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty"` - Items []GitopsCluster `json:"items"` + Items []GitOpsCluster `json:"items"` } func init() { - SchemeBuilder.Register(&GitopsCluster{}, &GitopsClusterList{}) + SchemeBuilder.Register(&GitOpsCluster{}, &GitOpsClusterList{}) } diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 213a72c..32b5949 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -1,4 +1,5 @@ //go:build !ignore_autogenerated +// +build !ignore_autogenerated /* Copyright 2022. @@ -27,7 +28,7 @@ import ( ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *GitopsCluster) DeepCopyInto(out *GitopsCluster) { +func (in *GitOpsCluster) DeepCopyInto(out *GitOpsCluster) { *out = *in out.TypeMeta = in.TypeMeta in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) @@ -35,18 +36,18 @@ func (in *GitopsCluster) DeepCopyInto(out *GitopsCluster) { in.Status.DeepCopyInto(&out.Status) } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitopsCluster. -func (in *GitopsCluster) DeepCopy() *GitopsCluster { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitOpsCluster. +func (in *GitOpsCluster) DeepCopy() *GitOpsCluster { if in == nil { return nil } - out := new(GitopsCluster) + out := new(GitOpsCluster) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *GitopsCluster) DeepCopyObject() runtime.Object { +func (in *GitOpsCluster) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -54,31 +55,31 @@ func (in *GitopsCluster) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *GitopsClusterList) DeepCopyInto(out *GitopsClusterList) { +func (in *GitOpsClusterList) DeepCopyInto(out *GitOpsClusterList) { *out = *in out.TypeMeta = in.TypeMeta in.ListMeta.DeepCopyInto(&out.ListMeta) if in.Items != nil { in, out := &in.Items, &out.Items - *out = make([]GitopsCluster, len(*in)) + *out = make([]GitOpsCluster, len(*in)) for i := range *in { (*in)[i].DeepCopyInto(&(*out)[i]) } } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitopsClusterList. -func (in *GitopsClusterList) DeepCopy() *GitopsClusterList { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitOpsClusterList. +func (in *GitOpsClusterList) DeepCopy() *GitOpsClusterList { if in == nil { return nil } - out := new(GitopsClusterList) + out := new(GitOpsClusterList) in.DeepCopyInto(out) return out } // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *GitopsClusterList) DeepCopyObject() runtime.Object { +func (in *GitOpsClusterList) DeepCopyObject() runtime.Object { if c := in.DeepCopy(); c != nil { return c } @@ -86,7 +87,7 @@ func (in *GitopsClusterList) DeepCopyObject() runtime.Object { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *GitopsClusterSpec) DeepCopyInto(out *GitopsClusterSpec) { +func (in *GitOpsClusterSpec) DeepCopyInto(out *GitOpsClusterSpec) { *out = *in if in.SecretRef != nil { in, out := &in.SecretRef, &out.SecretRef @@ -100,18 +101,18 @@ func (in *GitopsClusterSpec) DeepCopyInto(out *GitopsClusterSpec) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitopsClusterSpec. -func (in *GitopsClusterSpec) DeepCopy() *GitopsClusterSpec { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitOpsClusterSpec. +func (in *GitOpsClusterSpec) DeepCopy() *GitOpsClusterSpec { if in == nil { return nil } - out := new(GitopsClusterSpec) + out := new(GitOpsClusterSpec) in.DeepCopyInto(out) return out } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *GitopsClusterStatus) DeepCopyInto(out *GitopsClusterStatus) { +func (in *GitOpsClusterStatus) DeepCopyInto(out *GitOpsClusterStatus) { *out = *in if in.Conditions != nil { in, out := &in.Conditions, &out.Conditions @@ -122,12 +123,12 @@ func (in *GitopsClusterStatus) DeepCopyInto(out *GitopsClusterStatus) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitopsClusterStatus. -func (in *GitopsClusterStatus) DeepCopy() *GitopsClusterStatus { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GitOpsClusterStatus. +func (in *GitOpsClusterStatus) DeepCopy() *GitOpsClusterStatus { if in == nil { return nil } - out := new(GitopsClusterStatus) + out := new(GitOpsClusterStatus) in.DeepCopyInto(out) return out } diff --git a/config/crd/bases/gitops.weave.works_gitopsclusters.yaml b/config/crd/bases/gitops.weave.works_gitopsclusters.yaml index bbf7061..26f756c 100644 --- a/config/crd/bases/gitops.weave.works_gitopsclusters.yaml +++ b/config/crd/bases/gitops.weave.works_gitopsclusters.yaml @@ -3,13 +3,14 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: v0.13.0 + controller-gen.kubebuilder.io/version: v0.11.0 + creationTimestamp: null name: gitopsclusters.gitops.weave.works spec: group: gitops.weave.works names: - kind: GitopsCluster - listKind: GitopsClusterList + kind: GitOpsCluster + listKind: GitOpsClusterList plural: gitopsclusters singular: gitopscluster scope: Namespaced @@ -30,7 +31,7 @@ spec: name: v1alpha1 schema: openAPIV3Schema: - description: GitopsCluster is the Schema for the gitopsclusters API + description: GitOpsCluster is the Schema for the gitopsclusters API properties: apiVersion: description: 'APIVersion defines the versioned schema of this representation @@ -45,7 +46,7 @@ spec: metadata: type: object spec: - description: GitopsClusterSpec defines the desired state of GitopsCluster + description: GitOpsClusterSpec defines the desired state of GitOpsCluster properties: capiClusterRef: description: CAPIClusterRef specifies the CAPI Cluster. @@ -73,7 +74,7 @@ spec: - message: cannot provide both capiClusterRef and secretRef rule: '!(has(self.secretRef) && has(self.capiClusterRef))' status: - description: GitopsClusterStatus defines the observed state of GitopsCluster + description: GitOpsClusterStatus defines the observed state of GitOpsCluster properties: conditions: description: Conditions holds the conditions for the Cluster. @@ -147,7 +148,7 @@ spec: type: object type: object x-kubernetes-validations: - - message: must configure spec + - message: must confgure spec rule: has(self.spec) served: true storage: true diff --git a/config/rbac/role.yaml b/config/rbac/role.yaml index 733aec1..52629d1 100644 --- a/config/rbac/role.yaml +++ b/config/rbac/role.yaml @@ -2,6 +2,7 @@ apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: + creationTimestamp: null name: manager-role rules: - apiGroups: diff --git a/config/samples/gitops_v1alpha1_gitopscluster_capi.yaml b/config/samples/gitops_v1alpha1_gitopscluster_capi.yaml index 3ffd964..eeeecc2 100644 --- a/config/samples/gitops_v1alpha1_gitopscluster_capi.yaml +++ b/config/samples/gitops_v1alpha1_gitopscluster_capi.yaml @@ -1,5 +1,5 @@ apiVersion: gitops.weave.works/v1alpha1 -kind: GitopsCluster +kind: GitOpsCluster metadata: name: dev namespace: default diff --git a/config/samples/gitops_v1alpha1_gitopscluster_secret.yaml b/config/samples/gitops_v1alpha1_gitopscluster_secret.yaml index db53a35..64b2304 100644 --- a/config/samples/gitops_v1alpha1_gitopscluster_secret.yaml +++ b/config/samples/gitops_v1alpha1_gitopscluster_secret.yaml @@ -1,5 +1,5 @@ apiVersion: gitops.weave.works/v1alpha1 -kind: GitopsCluster +kind: GitOpsCluster metadata: name: dev namespace: default diff --git a/controllers/gitopscluster_controller.go b/controllers/gitopscluster_controller.go index 5e81ffd..ead5275 100644 --- a/controllers/gitopscluster_controller.go +++ b/controllers/gitopscluster_controller.go @@ -39,14 +39,14 @@ import ( "sigs.k8s.io/controller-runtime/pkg/handler" "sigs.k8s.io/controller-runtime/pkg/log" - gitopsv1alpha1 "github.com/weaveworks/cluster-controller/api/v1alpha1" + gitopsv1alpha1 "github.com/gitops-tools/cluster-controller/api/v1alpha1" ) // GitOpsClusterFinalizer is the finalizer key used to detect when we need to -// finalize a Gitops cluster. +// finalize a GitOps cluster. const GitOpsClusterFinalizer = "clusters.gitops.weave.works" -// GitOpsClusterProvisionedAnnotation if applied to a GitopsCluster indicates +// GitOpsClusterProvisionedAnnotation if applied to a GitOpsCluster indicates // that it should have a ready Provisioned condition. const GitOpsClusterProvisionedAnnotation = "clusters.gitops.weave.works/provisioned" @@ -63,8 +63,8 @@ const ( MissingSecretRequeueTime = time.Second * 30 ) -// GitopsClusterReconciler reconciles a GitopsCluster object -type GitopsClusterReconciler struct { +// GitOpsClusterReconciler reconciles a GitOpsCluster object +type GitOpsClusterReconciler struct { client.Client Scheme *runtime.Scheme Options Options @@ -78,10 +78,10 @@ type Options struct { DefaultRequeueTime time.Duration } -// NewGitopsClusterReconciler creates and returns a configured +// NewGitOpsClusterReconciler creates and returns a configured // reconciler ready for use. -func NewGitopsClusterReconciler(c client.Client, s *runtime.Scheme, opts Options) *GitopsClusterReconciler { - return &GitopsClusterReconciler{ +func NewGitOpsClusterReconciler(c client.Client, s *runtime.Scheme, opts Options) *GitOpsClusterReconciler { + return &GitOpsClusterReconciler{ Client: c, Scheme: s, Options: opts, @@ -97,11 +97,11 @@ func NewGitopsClusterReconciler(c client.Client, s *runtime.Scheme, opts Options // Reconcile is part of the main kubernetes reconciliation loop which aims to // move the current state of the cluster closer to the desired state. -func (r *GitopsClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { +func (r *GitOpsClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) { log := log.FromContext(ctx) // Fetch the Cluster - cluster := &gitopsv1alpha1.GitopsCluster{} + cluster := &gitopsv1alpha1.GitOpsCluster{} if err := r.Get(ctx, req.NamespacedName, cluster); err != nil { return ctrl.Result{}, client.IgnoreNotFound(err) } @@ -167,7 +167,7 @@ func (r *GitopsClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reques e := fmt.Errorf("failed to get secret %q: %w", name, err) if apierrors.IsNotFound(err) { // TODO: this could _possibly_ be controllable by the - // `GitopsCluster` itself. + // `GitOpsCluster` itself. log.Info("waiting for cluster secret to be available") conditions.MarkFalse(cluster, meta.ReadyCondition, gitopsv1alpha1.WaitingForSecretReason, e.Error()) if err := r.Status().Update(ctx, cluster); err != nil { @@ -234,7 +234,7 @@ func (r *GitopsClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reques return ctrl.Result{RequeueAfter: r.Options.DefaultRequeueTime}, nil } -func (r *GitopsClusterReconciler) reconcileDeletedReferences(ctx context.Context, gc *gitopsv1alpha1.GitopsCluster) error { +func (r *GitOpsClusterReconciler) reconcileDeletedReferences(ctx context.Context, gc *gitopsv1alpha1.GitOpsCluster) error { log := log.FromContext(ctx) if gc.Spec.CAPIClusterRef != nil { @@ -281,17 +281,17 @@ func (r *GitopsClusterReconciler) reconcileDeletedReferences(ctx context.Context } // SetupWithManager sets up the controller with the Manager. -func (r *GitopsClusterReconciler) SetupWithManager(mgr ctrl.Manager) error { - if err := mgr.GetCache().IndexField(context.TODO(), &gitopsv1alpha1.GitopsCluster{}, SecretNameIndexKey, r.indexGitopsClusterBySecretName); err != nil { +func (r *GitOpsClusterReconciler) SetupWithManager(mgr ctrl.Manager) error { + if err := mgr.GetCache().IndexField(context.TODO(), &gitopsv1alpha1.GitOpsCluster{}, SecretNameIndexKey, r.indexGitOpsClusterBySecretName); err != nil { return fmt.Errorf("failed setting index fields: %w", err) } - if err := mgr.GetCache().IndexField(context.TODO(), &gitopsv1alpha1.GitopsCluster{}, CAPIClusterNameIndexKey, r.indexGitopsClusterByCAPIClusterName); err != nil { + if err := mgr.GetCache().IndexField(context.TODO(), &gitopsv1alpha1.GitOpsCluster{}, CAPIClusterNameIndexKey, r.indexGitOpsClusterByCAPIClusterName); err != nil { return fmt.Errorf("failed setting index fields: %w", err) } builder := ctrl.NewControllerManagedBy(mgr). - For(&gitopsv1alpha1.GitopsCluster{}). + For(&gitopsv1alpha1.GitOpsCluster{}). Watches( &corev1.Secret{}, handler.EnqueueRequestsFromMapFunc(r.requestsForSecretChange), @@ -308,10 +308,10 @@ func (r *GitopsClusterReconciler) SetupWithManager(mgr ctrl.Manager) error { return builder.Complete(r) } -func (r *GitopsClusterReconciler) indexGitopsClusterBySecretName(o client.Object) []string { - c, ok := o.(*gitopsv1alpha1.GitopsCluster) +func (r *GitOpsClusterReconciler) indexGitOpsClusterBySecretName(o client.Object) []string { + c, ok := o.(*gitopsv1alpha1.GitOpsCluster) if !ok { - panic(fmt.Sprintf("Expected a GitopsCluster, got %T", o)) + panic(fmt.Sprintf("Expected a GitOpsCluster, got %T", o)) } if c.Spec.SecretRef != nil { @@ -321,10 +321,10 @@ func (r *GitopsClusterReconciler) indexGitopsClusterBySecretName(o client.Object return nil } -func (r *GitopsClusterReconciler) indexGitopsClusterByCAPIClusterName(o client.Object) []string { - c, ok := o.(*gitopsv1alpha1.GitopsCluster) +func (r *GitOpsClusterReconciler) indexGitOpsClusterByCAPIClusterName(o client.Object) []string { + c, ok := o.(*gitopsv1alpha1.GitOpsCluster) if !ok { - panic(fmt.Sprintf("Expected a GitopsCluster, got %T", o)) + panic(fmt.Sprintf("Expected a GitOpsCluster, got %T", o)) } if c.Spec.CAPIClusterRef != nil { @@ -334,13 +334,13 @@ func (r *GitopsClusterReconciler) indexGitopsClusterByCAPIClusterName(o client.O return nil } -func (r *GitopsClusterReconciler) requestsForSecretChange(ctx context.Context, o client.Object) []ctrl.Request { +func (r *GitOpsClusterReconciler) requestsForSecretChange(ctx context.Context, o client.Object) []ctrl.Request { secret, ok := o.(*corev1.Secret) if !ok { panic(fmt.Sprintf("Expected a Secret but got a %T", o)) } - var list gitopsv1alpha1.GitopsClusterList + var list gitopsv1alpha1.GitOpsClusterList if err := r.Client.List(ctx, &list, client.MatchingFields{SecretNameIndexKey: secret.GetName()}); err != nil { return nil } @@ -353,13 +353,13 @@ func (r *GitopsClusterReconciler) requestsForSecretChange(ctx context.Context, o return reqs } -func (r *GitopsClusterReconciler) requestsForCAPIClusterChange(ctx context.Context, o client.Object) []ctrl.Request { +func (r *GitOpsClusterReconciler) requestsForCAPIClusterChange(ctx context.Context, o client.Object) []ctrl.Request { cluster, ok := o.(*clusterv1.Cluster) if !ok { panic(fmt.Sprintf("Expected a CAPI Cluster but got a %T", o)) } - var list gitopsv1alpha1.GitopsClusterList + var list gitopsv1alpha1.GitOpsClusterList if err := r.Client.List(ctx, &list, client.MatchingFields{CAPIClusterNameIndexKey: cluster.GetName()}); err != nil { return nil } @@ -372,7 +372,7 @@ func (r *GitopsClusterReconciler) requestsForCAPIClusterChange(ctx context.Conte return reqs } -func (r *GitopsClusterReconciler) verifyConnectivity(ctx context.Context, cluster *gitopsv1alpha1.GitopsCluster) error { +func (r *GitOpsClusterReconciler) verifyConnectivity(ctx context.Context, cluster *gitopsv1alpha1.GitOpsCluster) error { log := log.FromContext(ctx) // avoid checking the cluster if it's under deletion. @@ -422,7 +422,7 @@ func (r *GitopsClusterReconciler) verifyConnectivity(ctx context.Context, cluste return nil } -func (r *GitopsClusterReconciler) restConfigFromSecret(ctx context.Context, cluster *gitopsv1alpha1.GitopsCluster) (*rest.Config, error) { +func (r *GitOpsClusterReconciler) restConfigFromSecret(ctx context.Context, cluster *gitopsv1alpha1.GitOpsCluster) (*rest.Config, error) { log := log.FromContext(ctx) var secretRef string diff --git a/controllers/gitopscluster_controller_test.go b/controllers/gitopscluster_controller_test.go index ee5f476..3ed522b 100644 --- a/controllers/gitopscluster_controller_test.go +++ b/controllers/gitopscluster_controller_test.go @@ -9,8 +9,8 @@ import ( "github.com/fluxcd/pkg/apis/meta" "github.com/fluxcd/pkg/runtime/conditions" - gitopsv1alpha1 "github.com/weaveworks/cluster-controller/api/v1alpha1" - "github.com/weaveworks/cluster-controller/controllers" + gitopsv1alpha1 "github.com/gitops-tools/cluster-controller/api/v1alpha1" + "github.com/gitops-tools/cluster-controller/controllers" corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -48,7 +48,7 @@ func TestReconcile(t *testing.T) { { name: "secret does not exist", state: []runtime.Object{ - makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.Spec.SecretRef = &meta.LocalObjectReference{ Name: "missing", } @@ -67,7 +67,7 @@ func TestReconcile(t *testing.T) { { name: "secret exists", state: []runtime.Object{ - makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.Spec.SecretRef = &meta.LocalObjectReference{ Name: "dev", } @@ -90,7 +90,7 @@ func TestReconcile(t *testing.T) { { name: "non-CAPI cluster has provisioned annotation", state: []runtime.Object{ - makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.ObjectMeta.Annotations = map[string]string{ controllers.GitOpsClusterProvisionedAnnotation: "true", } @@ -110,7 +110,7 @@ func TestReconcile(t *testing.T) { { name: "CAPI cluster does not exist", state: []runtime.Object{ - makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.Spec.CAPIClusterRef = &meta.LocalObjectReference{ Name: "missing", } @@ -129,7 +129,7 @@ func TestReconcile(t *testing.T) { { name: "CAPI cluster exists but is not ready", state: []runtime.Object{ - makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.Spec.CAPIClusterRef = &meta.LocalObjectReference{ Name: "dev", } @@ -152,7 +152,7 @@ func TestReconcile(t *testing.T) { { name: "CAPI cluster exists and is provisioned", state: []runtime.Object{ - makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.Spec.CAPIClusterRef = &meta.LocalObjectReference{ Name: "dev", } @@ -177,7 +177,7 @@ func TestReconcile(t *testing.T) { { name: "CAPI cluster exists and is ready", state: []runtime.Object{ - makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.Spec.CAPIClusterRef = &meta.LocalObjectReference{ Name: "dev", } @@ -202,7 +202,7 @@ func TestReconcile(t *testing.T) { { name: "CAPI component is not enabled", state: []runtime.Object{ - makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.Spec.CAPIClusterRef = &meta.LocalObjectReference{ Name: "dev", } @@ -219,7 +219,7 @@ func TestReconcile(t *testing.T) { { name: "verify connectivity to the cluster", state: []runtime.Object{ - makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.Spec.SecretRef = &meta.LocalObjectReference{ Name: "dev", } @@ -242,7 +242,7 @@ func TestReconcile(t *testing.T) { { name: "verify connectivity failed to read secret", state: []runtime.Object{ - makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.Spec.SecretRef = &meta.LocalObjectReference{ Name: "dev", } @@ -265,7 +265,7 @@ func TestReconcile(t *testing.T) { { name: "verify connectivity failed to connect", state: []runtime.Object{ - makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.Spec.SecretRef = &meta.LocalObjectReference{ Name: "dev", } @@ -302,7 +302,7 @@ func TestReconcile(t *testing.T) { assertErrorMatch(t, tt.errString, err) clsObjectKey := types.NamespacedName{Namespace: testNamespace, Name: testName} - cls := testGetGitopsCluster(t, r.Client, clsObjectKey) + cls := testGetGitOpsCluster(t, r.Client, clsObjectKey) assertClusterStatus(t, cls, tt.wantCondition, tt.wantStatus, tt.wantStatusMessage) }) } @@ -311,7 +311,7 @@ func TestReconcile(t *testing.T) { func TestFinalizedDeletion(t *testing.T) { finalizerTests := []struct { name string - gitopsCluster *gitopsv1alpha1.GitopsCluster + gitopsCluster *gitopsv1alpha1.GitOpsCluster additionalObjs []runtime.Object wantStatusReason string @@ -320,7 +320,7 @@ func TestFinalizedDeletion(t *testing.T) { }{ { "when CAPI cluster exists", - makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.ObjectMeta.Namespace = "test-ns" c.Spec.CAPIClusterRef = &meta.LocalObjectReference{ Name: "test-cluster", @@ -333,7 +333,7 @@ func TestFinalizedDeletion(t *testing.T) { }, { "when CAPI cluster has been deleted", - makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.ObjectMeta.Namespace = "test-ns" c.Spec.CAPIClusterRef = &meta.LocalObjectReference{ Name: "test-cluster", @@ -346,7 +346,7 @@ func TestFinalizedDeletion(t *testing.T) { }, { "when referenced secret exists", - makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.ObjectMeta.Namespace = "test-ns" c.Spec.SecretRef = &meta.LocalObjectReference{ Name: "test-cluster", @@ -360,7 +360,7 @@ func TestFinalizedDeletion(t *testing.T) { }, { "when referenced secret has been deleted", - makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.ObjectMeta.Namespace = "test-ns" c.Spec.SecretRef = &meta.LocalObjectReference{ Name: "test-cluster", @@ -391,7 +391,7 @@ func TestFinalizedDeletion(t *testing.T) { assertErrorMatch(t, tt.errString, err) if tt.clusterExists { - updated := testGetGitopsCluster(t, r.Client, client.ObjectKeyFromObject(tt.gitopsCluster)) + updated := testGetGitOpsCluster(t, r.Client, client.ObjectKeyFromObject(tt.gitopsCluster)) cond := conditions.Get(updated, meta.ReadyCondition) if cond != nil { @@ -400,7 +400,7 @@ func TestFinalizedDeletion(t *testing.T) { } } } else { - var cluster gitopsv1alpha1.GitopsCluster + var cluster gitopsv1alpha1.GitOpsCluster err := r.Client.Get(context.TODO(), client.ObjectKeyFromObject(tt.gitopsCluster), &cluster) if !apierrors.IsNotFound(err) { t.Fatalf("expected cluster to not exist but got cluster %v", cluster) @@ -413,14 +413,14 @@ func TestFinalizedDeletion(t *testing.T) { func TestFinalizers(t *testing.T) { finalizerTests := []struct { name string - gitopsCluster *gitopsv1alpha1.GitopsCluster + gitopsCluster *gitopsv1alpha1.GitOpsCluster additionalObjs []runtime.Object wantFinalizer bool }{ { "when cluster has no other reference", - makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.ObjectMeta.Namespace = "test-ns" }), []runtime.Object{}, @@ -428,7 +428,7 @@ func TestFinalizers(t *testing.T) { }, { "cluster referencing CAPI cluster", - makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.ObjectMeta.Namespace = "test-ns" c.Spec.CAPIClusterRef = &meta.LocalObjectReference{ Name: "test-cluster", @@ -439,7 +439,7 @@ func TestFinalizers(t *testing.T) { }, { "cluster referencing CAPI cluster but capi-enabled is false", - makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.ObjectMeta.Namespace = "test-ns" c.Spec.CAPIClusterRef = &meta.LocalObjectReference{ Name: "test-cluster", @@ -450,7 +450,7 @@ func TestFinalizers(t *testing.T) { }, { "cluster referencing secret", - makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.ObjectMeta.Namespace = "test-ns" c.Spec.SecretRef = &meta.LocalObjectReference{ Name: "test-cluster", @@ -462,7 +462,7 @@ func TestFinalizers(t *testing.T) { }, { "cluster referencing secret - but no-secret-finalization annotation", - makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.ObjectMeta.Namespace = "test-ns" c.ObjectMeta.Annotations = map[string]string{ gitopsv1alpha1.GitOpsClusterNoSecretFinalizerAnnotation: "true", @@ -478,7 +478,7 @@ func TestFinalizers(t *testing.T) { { "deleted gitops cluster", - makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { now := metav1.NewTime(time.Now()) c.ObjectMeta.Namespace = "test-ns" c.ObjectMeta.Finalizers = []string{"testing"} @@ -508,7 +508,7 @@ func TestFinalizers(t *testing.T) { t.Fatal(err) } - updated := testGetGitopsCluster(t, r.Client, client.ObjectKeyFromObject(tt.gitopsCluster)) + updated := testGetGitOpsCluster(t, r.Client, client.ObjectKeyFromObject(tt.gitopsCluster)) if v := controllerutil.ContainsFinalizer(updated, controllers.GitOpsClusterFinalizer); v != tt.wantFinalizer { t.Fatalf("cluster HasFinalizer got %v, want %v", v, tt.wantFinalizer) } @@ -516,7 +516,7 @@ func TestFinalizers(t *testing.T) { } } -func TestGitopsClusterValidation(t *testing.T) { +func TestGitOpsClusterValidation(t *testing.T) { testEnv := &envtest.Environment{ CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")}, } @@ -541,7 +541,7 @@ func TestGitopsClusterValidation(t *testing.T) { } t.Run("when neither the secret nor capi cluster are configured", func(t *testing.T) { - testCluster := makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + testCluster := makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.ObjectMeta.Name = "no-config" c.ObjectMeta.Namespace = "default" c.Spec.SecretRef = nil @@ -554,7 +554,7 @@ func TestGitopsClusterValidation(t *testing.T) { }) t.Run("when both the secret and capi cluster are configured", func(t *testing.T) { - testCluster := makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + testCluster := makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.ObjectMeta.Name = "both-configs" c.ObjectMeta.Namespace = "default" c.Spec.SecretRef = &meta.LocalObjectReference{ @@ -571,7 +571,7 @@ func TestGitopsClusterValidation(t *testing.T) { }) t.Run("when the secret is configured", func(t *testing.T) { - testCluster := makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + testCluster := makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.ObjectMeta.Name = "only-secret-configured" c.ObjectMeta.Namespace = "default" c.Spec.SecretRef = &meta.LocalObjectReference{ @@ -583,7 +583,7 @@ func TestGitopsClusterValidation(t *testing.T) { }) t.Run("when the capiClusterRef is configured", func(t *testing.T) { - testCluster := makeTestCluster(func(c *gitopsv1alpha1.GitopsCluster) { + testCluster := makeTestCluster(func(c *gitopsv1alpha1.GitOpsCluster) { c.ObjectMeta.Name = "only-capi-cluster-configured" c.ObjectMeta.Namespace = "default" c.Spec.CAPIClusterRef = &meta.LocalObjectReference{ @@ -596,16 +596,16 @@ func TestGitopsClusterValidation(t *testing.T) { } -func makeTestReconciler(t *testing.T, opts controllers.Options, objs ...runtime.Object) *controllers.GitopsClusterReconciler { +func makeTestReconciler(t *testing.T, opts controllers.Options, objs ...runtime.Object) *controllers.GitOpsClusterReconciler { s, tc := makeTestClientAndScheme(t, opts, objs...) - return controllers.NewGitopsClusterReconciler(tc, s, opts) + return controllers.NewGitOpsClusterReconciler(tc, s, opts) } func makeTestClientAndScheme(t *testing.T, opts controllers.Options, objs ...runtime.Object) (*runtime.Scheme, client.Client) { s := makeClusterScheme(t, opts) return s, fake.NewClientBuilder(). WithScheme(s). - WithStatusSubresource(&gitopsv1alpha1.GitopsCluster{}). + WithStatusSubresource(&gitopsv1alpha1.GitOpsCluster{}). WithRuntimeObjects(objs...).Build() } @@ -629,13 +629,13 @@ func assertNoError(t *testing.T, err error) { } } -func makeTestCluster(opts ...func(*gitopsv1alpha1.GitopsCluster)) *gitopsv1alpha1.GitopsCluster { - c := &gitopsv1alpha1.GitopsCluster{ +func makeTestCluster(opts ...func(*gitopsv1alpha1.GitOpsCluster)) *gitopsv1alpha1.GitOpsCluster { + c := &gitopsv1alpha1.GitOpsCluster{ ObjectMeta: metav1.ObjectMeta{ Name: testName, Namespace: testNamespace, }, - Spec: gitopsv1alpha1.GitopsClusterSpec{}, + Spec: gitopsv1alpha1.GitOpsClusterSpec{}, } for _, o := range opts { o(c) @@ -696,16 +696,16 @@ func matchErrorString(t *testing.T, s string, e error) bool { return match } -func testGetGitopsCluster(t *testing.T, c client.Client, k client.ObjectKey) *gitopsv1alpha1.GitopsCluster { +func testGetGitOpsCluster(t *testing.T, c client.Client, k client.ObjectKey) *gitopsv1alpha1.GitOpsCluster { t.Helper() - var cluster gitopsv1alpha1.GitopsCluster + var cluster gitopsv1alpha1.GitOpsCluster if err := c.Get(context.TODO(), k, &cluster); err != nil { t.Fatal(err) } return &cluster } -func assertClusterStatus(t *testing.T, cls *gitopsv1alpha1.GitopsCluster, condType string, status metav1.ConditionStatus, msg string) { +func assertClusterStatus(t *testing.T, cls *gitopsv1alpha1.GitOpsCluster, condType string, status metav1.ConditionStatus, msg string) { t.Helper() cond := conditions.Get(cls, condType) if status == "" { diff --git a/controllers/suite_test.go b/controllers/suite_test.go index c4ad94e..990821b 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -23,13 +23,13 @@ import ( "path/filepath" "testing" - "github.com/weaveworks/cluster-controller/controllers" + "github.com/gitops-tools/cluster-controller/controllers" "k8s.io/client-go/kubernetes/scheme" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/envtest" - gitopsv1alpha1 "github.com/weaveworks/cluster-controller/api/v1alpha1" + gitopsv1alpha1 "github.com/gitops-tools/cluster-controller/api/v1alpha1" //+kubebuilder:scaffold:imports ) @@ -64,7 +64,7 @@ func TestMain(m *testing.M) { err = gitopsv1alpha1.AddToScheme(scheme.Scheme) if err != nil { - log.Fatalf("add GitopsCluster to schema failed: %s", err) + log.Fatalf("add GitOpsCluster to schema failed: %s", err) } k8sManager, err = ctrl.NewManager(cfg, ctrl.Options{ @@ -74,7 +74,7 @@ func TestMain(m *testing.M) { log.Fatalf("initializing controller manager failed: %s", err) } - r := controllers.NewGitopsClusterReconciler(k8sManager.GetClient(), scheme.Scheme, controllers.Options{}) + r := controllers.NewGitOpsClusterReconciler(k8sManager.GetClient(), scheme.Scheme, controllers.Options{}) err = (r).SetupWithManager(k8sManager) if err != nil { log.Fatalf("setup cluster controller failed: %s", err) diff --git a/go.mod b/go.mod index 22926b6..737495d 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ -module github.com/weaveworks/cluster-controller +module github.com/gitops-tools/cluster-controller -go 1.20 +go 1.22 require ( github.com/fluxcd/pkg/apis/meta v1.1.2 diff --git a/main.go b/main.go index 39765e1..9302717 100644 --- a/main.go +++ b/main.go @@ -25,9 +25,9 @@ import ( _ "k8s.io/client-go/plugin/pkg/client/auth" "github.com/fluxcd/pkg/runtime/logger" + gitopsv1alpha1 "github.com/gitops-tools/cluster-controller/api/v1alpha1" + "github.com/gitops-tools/cluster-controller/controllers" flag "github.com/spf13/pflag" - gitopsv1alpha1 "github.com/weaveworks/cluster-controller/api/v1alpha1" - "github.com/weaveworks/cluster-controller/controllers" "k8s.io/apimachinery/pkg/runtime" utilruntime "k8s.io/apimachinery/pkg/util/runtime" clientgoscheme "k8s.io/client-go/kubernetes/scheme" @@ -102,8 +102,8 @@ func main() { os.Exit(1) } - if err = controllers.NewGitopsClusterReconciler(mgr.GetClient(), mgr.GetScheme(), options).SetupWithManager(mgr); err != nil { - setupLog.Error(err, "unable to create controller", "controller", "GitopsCluster") + if err = controllers.NewGitOpsClusterReconciler(mgr.GetClient(), mgr.GetScheme(), options).SetupWithManager(mgr); err != nil { + setupLog.Error(err, "unable to create controller", "controller", "GitOpsCluster") os.Exit(1) } //+kubebuilder:scaffold:builder