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

feat: Implement reconcile logic #3

Merged
merged 1 commit into from Mar 29, 2022
Merged

feat: Implement reconcile logic #3

merged 1 commit into from Mar 29, 2022

Conversation

yiannistri
Copy link
Collaborator

@yiannistri yiannistri commented Mar 22, 2022

Fixes: weaveworks/weave-gitops-enterprise#487

  • Set condition when secret/CAPI cluster is found/not found
  • Add watches for secrets/CAPI clusters to ensure reconcile function is being called when they get updated

api/v1alpha1/cluster_types.go Outdated Show resolved Hide resolved
controllers/cluster_controller.go Outdated Show resolved Hide resolved
controllers/cluster_controller.go Outdated Show resolved Hide resolved
controllers/cluster_controller.go Outdated Show resolved Hide resolved
controllers/cluster_controller.go Outdated Show resolved Hide resolved
controllers/cluster_controller_test.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@foot foot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code lgtm! Will try and do a quick run..

api/v1alpha1/cluster_types.go Outdated Show resolved Hide resolved
controllers/cluster_controller.go Outdated Show resolved Hide resolved
controllers/cluster_controller.go Show resolved Hide resolved
@foot
Copy link
Collaborator

foot commented Mar 24, 2022

Maybe we could add a couple of examples too

@foot
Copy link
Collaborator

foot commented Mar 24, 2022

Ah here is one config/samples/gitops_v1alpha1_cluster_capi.yaml !

@foot
Copy link
Collaborator

foot commented Mar 24, 2022

I don't see the status getting updated on the cluster objects 🤔 .

kubectl apply -f config/samples/gitops_v1alpha1_cluster_secret.yaml
make run
ewq:~/weave/cluster-controller(controller-crd *=)$ kubectl get clusters
NAME   READY   STATUS
dev
ewq:~/weave/cluster-controller(controller-crd *=)$ kubectl create secret generic dev --from-literal foo=bar
secret/dev created
ewq:~/weave/cluster-controller(controller-crd *=)$ kubectl get clusters
NAME   READY   STATUS
dev

Though the controller does show stuff going on the logs:

...

1.6481100800010188e+09  ERROR   controller.cluster      Reconciler error        {"reconciler group": "gitops.weave.works", "reconciler kind": "Cluster", "name": "dev", "namespace": "default", "e
rror": "failed to get secret \"default/dev\": Secret \"dev\" not found"}

...

1.6481101753450072e+09  INFO    controller.cluster      Secret found    {"reconciler group": "gitops.weave.works", "reconciler kind": "Cluster", "name": "dev", "namespace": "default", "secret": {"namespace": "default", "name": "dev"}}

@yiannistri yiannistri force-pushed the controller-crd branch 2 times, most recently from ec29f17 to 22a2e8b Compare March 24, 2022 15:50
Copy link
Collaborator

@foot foot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome :)

var secret corev1.Secret
if err := r.Get(ctx, name, &secret); err != nil {
e := fmt.Errorf("failed to get secret %q: %w", name, err)
conditions.MarkFalse(cluster, meta.ReadyCondition, gitopsv1alpha1.WaitingForSecretReason, e.Error())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't necessarily need to implement it in this branch but I don't think that the secret not being available isn't an error...it's somewhat expected.

Use https://pkg.go.dev/k8s.io/apimachinery/pkg/api/errors#IsNotFound and if the secret isn't found, I'd use a time-based RequeueAfter result.

If you return errors, you will get backoff, this will top out at 6m, but, as you can imagine, the longer you wait, the more likely it is that the secret will be available (because you're waiting for it to be created) so letting it backoff 'til the maximum means you'll wait for the longest period.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants