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

🌱 Adding controller runtime create #9736

Conversation

adilGhaffarDev
Copy link
Contributor

What this PR does / why we need it:
Adding controller runtime Create

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes part of #9696 , KubectlApply is still in use when we are applying with args.

Signed-off-by: muhammad adil ghaffar <muhammad.adil.ghaffar@est.tech>
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-area PR is missing an area label labels Nov 20, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign enxebre for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 20, 2023
@adilGhaffarDev
Copy link
Contributor Author

/test pull-cluster-api-e2e-full-main

@@ -386,7 +386,7 @@ func ClusterctlUpgradeSpec(ctx context.Context, inputGetter func() ClusterctlUpg
Expect(workloadClusterTemplate).ToNot(BeNil(), "Failed to get the cluster template")

log.Logf("Applying the cluster template yaml to the cluster")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
log.Logf("Applying the cluster template yaml to the cluster")
log.Logf("Creating the cluster template yaml to the cluster")

@@ -104,7 +104,7 @@ func ApplyAutoscalerToWorkloadCluster(ctx context.Context, input ApplyAutoscaler
},
})
Expect(err).ToNot(HaveOccurred(), "failed to parse %s", workloadYamlTemplate)
Expect(input.WorkloadClusterProxy.Apply(ctx, workloadYaml)).To(Succeed(), "failed to apply %s", workloadYamlTemplate)
Expect(input.WorkloadClusterProxy.Create(ctx, workloadYaml)).To(Succeed(), "failed to apply %s", workloadYamlTemplate)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Expect(input.WorkloadClusterProxy.Create(ctx, workloadYaml)).To(Succeed(), "failed to apply %s", workloadYamlTemplate)
Expect(input.WorkloadClusterProxy.Create(ctx, workloadYaml)).To(Succeed(), "failed to create %s", workloadYamlTemplate)

@furkatgofurov7
Copy link
Member

/area e2e-testing

@k8s-ci-robot k8s-ci-robot added area/e2e-testing Issues or PRs related to e2e testing and removed do-not-merge/needs-area PR is missing an area label labels Nov 20, 2023
@sbueringer
Copy link
Member

sbueringer commented Nov 20, 2023

@fabriziopandini Before I start reviewing this PR, do we have consensus in general that it would be a good thing to use the CR client instead of os.Exec + kubectl apply? I think it's a good thing to get rid of our dependency to a kubectl binary and use CR as library instead.

I think using create is a reasonable approach if we only use apply today when we want to create new resources. There is no apply in the CR client (we could think about patch/update, but if we don't need it, it's probably not worth it)

Something I didn't think about before. Potentially we want to keep the test coverage of actually using the kubectl binary like our users do. One difference is e.g. that kubectl apply adds the last-applied-configuration annotation

@@ -253,6 +259,27 @@ func (p *clusterProxy) Apply(ctx context.Context, resources []byte, args ...stri
return exec.KubectlApply(ctx, p.kubeconfigPath, resources, args...)
}

// Create creates using the controller-runtime client.
func (p *clusterProxy) Create(ctx context.Context, resources []byte) error {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need a create func? Why not use GetClient().Create ?

I'm a bit concerned about silently ignoring IsAlreadyExists errors on this level (could lead to all sorts of surprises for the caller of this func if its YAML is not deployed)

@sbueringer
Copy link
Member

sbueringer commented Nov 20, 2023

I went through the linked issues and I think the main thing we wanted to achieve was to get better error output. So instead of some unreadable ExitError (https://prow.k8s.io/view/gs/kubernetes-jenkins/logs/periodic-cluster-api-e2e-main/1722000996239937536) we wanted to get the actual output. I've opend a PR to improve that: #9737

Comment on lines +274 to +276
if apierrors.IsAlreadyExists(err) {
continue
}
Copy link
Member

Choose a reason for hiding this comment

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

kubectl create fails when the resource already exists, while apply informs (through logging) that the resource already exists, and updates it in place.

What problem are we trying to solve here?

Copy link
Member

Choose a reason for hiding this comment

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

@adilGhaffarDev
Copy link
Contributor Author

/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 27, 2023
@fabriziopandini
Copy link
Member

fabriziopandini commented Jan 15, 2024

Can we close this now that #9737 is merged?
(this will let us to cloase also #9731)

@adilGhaffarDev
Copy link
Contributor Author

/close because we merged #9737 which serves the same purpose

@sbueringer
Copy link
Member

/close

@k8s-ci-robot
Copy link
Contributor

@sbueringer: Closed this PR.

In response to this:

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/e2e-testing Issues or PRs related to e2e testing cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants