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

Add tests, fix permanent errors and inconsistent behavior in controllers (#164)Co-authored-by: calvix <vaclav@giantswarm.io> #164

Merged
merged 22 commits into from
Mar 10, 2023

Conversation

AndiDog
Copy link
Contributor

@AndiDog AndiDog commented Mar 9, 2023

Towards giantswarm/roadmap#2073, giantswarm/roadmap#1981. This is part of the attempt to get to a working release again, and allow some refactoring.

Tested together with giantswarm/cert-manager-app#295 and giantswarm/default-apps-aws#170 to ensure that we can actually release this. Since the controllers applied different policies, I've decided that we anyway keep IRSA enabled and therefore switched to only using the "allow both KIAM and IRSA" policy for consistency.

This also does not fix existing, malformed IAM resources. The future controller code should reconcile to the desired state, not "create once and then skip any further reconciliation runs". We will have to either implement that now, or go through MCs where the operator already ran and filled in the wrong info (e.g. grizzly-CertManager-Role).

This only hacks the existing code instead of making it nice. But at least we now have behavioral tests that can be reused and match the tooling we discussed as nice-to-have for unit tests.

P.S. This supersedes #161 after we had lots of productive discussion about test tooling, of which most is integrated here now.

@AndiDog AndiDog requested a review from a team March 9, 2023 12:44
Copy link
Member

@fiunchinho fiunchinho left a comment

Choose a reason for hiding this comment

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

I haven't finished, but I left a couple of questions/suggestions.


// irsa-operator may not have created the secret yet
if apierrors.IsNotFound(err) {
return ctrl.Result{Requeue: true, RequeueAfter: 1 * time.Minute}, err
Copy link
Member

Choose a reason for hiding this comment

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

If we return an error, it will be requeued by default. Do we want to requeue after specifically 1 minute? I'd either

return ctrl.Result{}, err

or log the error but don't return it

return ctrl.Result{Requeue: true, RequeueAfter: 1 * time.Minute}, nil

I think I'd choose the first approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked into controller-runtime and you're right. So the re-queueing on error fixed it for my cases, then. I'll change this.

@@ -126,7 +134,7 @@ func (r *AWSMachinePoolReconciler) Reconcile(ctx context.Context, req ctrl.Reque

// remove finalizer from AWSCluster
{
awsCluster, err := key.GetAWSClusterByName(ctx, r.Client, clusterName)
awsCluster, err := key.GetAWSClusterByName(ctx, r.Client, clusterName, awsMachinePool.GetNamespace())
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this controller reconciling awsmachinepools? How come we are adding and removing finalizers to / from AWSClusters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't answer that right now, but added it to giantswarm/roadmap#2113

return ctrl.Result{}, err
// IAM role for control plane may have been created already, but not known to IAM yet
// (returns `MalformedPolicyDocument: Invalid principal in policy: "AWS":"arn:aws:iam::[...]:role/control-plane-[...]"`)
return ctrl.Result{Requeue: true, RequeueAfter: 1 * time.Minute}, err
Copy link
Member

Choose a reason for hiding this comment

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

Same as above about requeuing.

Labels: map[string]string{
"cluster.x-k8s.io/cluster-name": "test-cluster",
},
Name: "my-awsc",
Copy link
Member

@fiunchinho fiunchinho Mar 9, 2023

Choose a reason for hiding this comment

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

Generally, the AWSCluster and Cluster share the same name.

Suggested change
Name: "my-awsc",
Name: "test-cluster",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They don't have to, and that's why we have to look up by label. This is strongly on purpose, to avoid wrong assumptions in the code.

@calvix calvix changed the title Add tests, fix permanent errors and inconsistent behavior in controllers Add tests, fix permanent errors and inconsistent behavior in controllers (#164)Co-authored-by: calvix <vaclav@giantswarm.io> Mar 10, 2023
@calvix calvix merged commit ab70160 into master Mar 10, 2023
@calvix calvix deleted the fix-iam-policy-cert-manager branch March 10, 2023 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants