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

bugfix: make sure ns exsit when create velero secret #426

Merged
merged 2 commits into from
Oct 30, 2023

Conversation

Xieql
Copy link
Contributor

@Xieql Xieql commented Oct 30, 2023

What type of PR is this?

/kind bug

What this PR does / why we need it:

Ensures namespace exists in the target cluster before creating secrets, preventing potential failures.

Adds logic to check for namespace existence and creates it if missing, prior to secret creation.

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

bugfix: make sure ns exsit when create velero secret

Signed-off-by: Xieql <xieqianglong@huawei.com>
@netlify
Copy link

netlify bot commented Oct 30, 2023

Deploy Preview for kurator-dev canceled.

Name Link
🔨 Latest commit 213637b
🔍 Latest deploy log https://app.netlify.com/sites/kurator-dev/deploys/653f9442c40f4a0008e50f51

@@ -210,9 +212,28 @@ func createNewSecretInFleetCluster(cluster *fleetCluster, newSecret *corev1.Secr
// Get the namespace of the secret
namespace := newSecret.Namespace

// Check if namespace exists
_, err := kubeClient.CoreV1().Namespaces().Get(context.TODO(), namespace, metav1.GetOptions{})
Copy link
Member

Choose a reason for hiding this comment

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

nit: reuse karmadautil.EnsureNamespaceExist

Copy link
Member

@hzxuzhonghu hzxuzhonghu left a comment

Choose a reason for hiding this comment

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

Nit: we should add plugin name in the logs, this can be in following pr

return fmt.Errorf("failed to check for namespace %s: %w", namespace, err)
}
}

// Create the new secret
if _, err := kubeClient.CoreV1().Secrets(namespace).Create(context.TODO(), newSecret, metav1.CreateOptions{}); err != nil && !apierrors.IsAlreadyExists(err) {
Copy link
Member

Choose a reason for hiding this comment

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

duplicate creating secret, though you have checked alkready exists

@kurator-bot kurator-bot added size/M and removed size/S labels Oct 30, 2023
Signed-off-by: Xieql <xieqianglong@huawei.com>
Copy link
Member

@hzxuzhonghu hzxuzhonghu left a comment

Choose a reason for hiding this comment

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

/lgtm

@kurator-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hzxuzhonghu

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

The pull request process is described 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

@kurator-bot
Copy link
Collaborator

In response to a cherrypick label: new pull request created: #429

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

Successfully merging this pull request may close these issues.

3 participants