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

🌱 replace exec with client create/update #10442

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cahillsf
Copy link
Member

@cahillsf cahillsf commented Apr 16, 2024

Which issue(s) this PR fixes:
Fixes #9696

/area ci

@k8s-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. area/ci Issues or PRs related to ci cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 16, 2024
@cahillsf cahillsf changed the title WIP replace exec with client create 🌱 WIP replace exec with client create Apr 16, 2024
@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 neolit123 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

@cahillsf
Copy link
Member Author

/test help

@k8s-ci-robot
Copy link
Contributor

@cahillsf: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test pull-cluster-api-build-main
  • /test pull-cluster-api-e2e-blocking-main
  • /test pull-cluster-api-e2e-conformance-ci-latest-main
  • /test pull-cluster-api-e2e-conformance-main
  • /test pull-cluster-api-e2e-dualstack-and-ipv6-main
  • /test pull-cluster-api-e2e-main
  • /test pull-cluster-api-e2e-mink8s-main
  • /test pull-cluster-api-e2e-upgrade-1-30-1-31-main
  • /test pull-cluster-api-test-main
  • /test pull-cluster-api-test-mink8s-main
  • /test pull-cluster-api-verify-main

The following commands are available to trigger optional jobs:

  • /test pull-cluster-api-apidiff-main

Use /test all to run the following jobs that were automatically triggered:

  • pull-cluster-api-apidiff-main
  • pull-cluster-api-build-main
  • pull-cluster-api-e2e-blocking-main
  • pull-cluster-api-test-main
  • pull-cluster-api-verify-main

In response to this:

/test help

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.

@cahillsf
Copy link
Member Author

/test pull-cluster-api-build-main

@cahillsf
Copy link
Member Author

/test pull-cluster-api-e2e-main

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels May 7, 2024
@cahillsf
Copy link
Member Author

/test pull-cluster-api-e2e-main

@cahillsf
Copy link
Member Author

/test pull-cluster-api-e2e-main

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 3, 2024
@cahillsf
Copy link
Member Author

cahillsf commented Jun 3, 2024

/test pull-cluster-api-e2e-main

@cahillsf cahillsf changed the title 🌱 WIP replace exec with client create 🌱 replace exec with client create/update Jun 4, 2024
@cahillsf cahillsf marked this pull request as ready for review June 4, 2024 01:00
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 4, 2024
@k8s-ci-robot k8s-ci-robot requested a review from elmiko June 4, 2024 01:00
if labelSelector.Matches(labels) {
if err := p.GetClient().Get(ctx, objectKey, existingObject); err != nil {
// Expected error -- if the object does not exist, create it
if strings.Contains(err.Error(), "not found") {
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to use apierrors.IsNotFound(err) from apierrors "k8s.io/apimachinery/pkg/api/errors" instead of string comparison?

Copy link
Member

Choose a reason for hiding this comment

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

Basically we could do something like

  if !apierrors.IsNotFound(err) {
    return retErrs = append(retErrs, err)
    continue
  }
  if err := p.GetClient().Create(ctx, &o); err != nil {
    retErrs = append(retErrs, err)
  }

return nil
existingObject := &unstructured.Unstructured{}
for _, o := range objs {
o := o
Copy link
Member

Choose a reason for hiding this comment

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

Not needed anymore in go 1.22

Suggested change
o := o

Copy link
Member Author

Choose a reason for hiding this comment

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

i thought so, but this kept getting flagged in the CI as an issue... struggling to find the results, will remove when i take into account your other feedback and see if it occurs again

Copy link
Member

Choose a reason for hiding this comment

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

ah then the linter fix is not yet merged I guess (sorry), fine to just make the linter happy 👍

@@ -358,7 +358,7 @@ func ApplyClusterTemplateAndWait(ctx context.Context, input ApplyClusterTemplate
WaitForControlPlaneIntervals: input.WaitForControlPlaneIntervals,
WaitForMachineDeployments: input.WaitForMachineDeployments,
WaitForMachinePools: input.WaitForMachinePools,
Args: input.Args,
LabelSelectors: input.Args,
Copy link
Member

Choose a reason for hiding this comment

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

we should rename input.Args too

if errors.As(err, &exitErr) {
return pkgerrors.New(fmt.Sprintf("%s: stderr: %s", err.Error(), exitErr.Stderr))
// Creates or updates objects using the clusterProxy client.
func (p *clusterProxy) CreateOrUpdate(ctx context.Context, resources []byte, selector ...string) error {
Copy link
Member

Choose a reason for hiding this comment

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

being able to provide selector ...string but only at the end allowing to pass a single one just to make the arg optional looks a bit weird and unclean to me.

We could do it similar to GetWorkloadCluster and be able to pass in some opts ...CreateOrUpdateOption, which would also make it somewhat extendable if required in future.

Copy link
Member Author

Choose a reason for hiding this comment

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

agreed, i wasnt too happy with this -- sounds good

@chrischdi
Copy link
Member

And thanks for tackling this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ci Issues or PRs related to ci cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace kubectl apply in e2e test framework
3 participants