-
Notifications
You must be signed in to change notification settings - Fork 38
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
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,7 +71,7 @@ func (f *FleetManager) reconcileBackupPlugin(ctx context.Context, fleet *v1alpha | |
// newSecret is a variable used to store the newly created secret object which contains the necessary credentials for the object storage provider. The specific structure and content of the secret vary depending on the provider. | ||
newSecret, err := f.buildNewSecret(ctx, veleroCfg.Storage.SecretName, objStoreProvider, fleetNN) | ||
if err != nil { | ||
log.Error(err, "failed to builder new object store secret") | ||
err = fmt.Errorf("error building new secret for objStoreProvider %s: %w", objStoreProvider, err) | ||
return nil, ctrl.Result{}, err | ||
} | ||
|
||
|
@@ -87,11 +87,13 @@ func (f *FleetManager) reconcileBackupPlugin(ctx context.Context, fleet *v1alpha | |
SecretKey: cluster.SecretKey, | ||
}, veleroCfg, newSecret.Name) | ||
if err != nil { | ||
err = fmt.Errorf("error rendering Velero for fleet cluster %s: %w", key.Name, err) | ||
return nil, ctrl.Result{}, err | ||
} | ||
|
||
// create a new secret in the current fleet cluster before initializing the backup plugin. | ||
if err := createNewSecretInFleetCluster(cluster, newSecret); err != nil { | ||
err = fmt.Errorf("error creating new secret in fleet cluster %s: %w", key.Name, err) | ||
return nil, ctrl.Result{}, err | ||
} | ||
|
||
|
@@ -117,7 +119,7 @@ func (f *FleetManager) reconcileBackupPlugin(ctx context.Context, fleet *v1alpha | |
// preventing orphaned resources and maintaining the cleanliness of the cluster. | ||
for key, cluster := range fleetClusters { | ||
if err := f.updateNewSecretOwnerReference(ctx, key.Name, cluster, newSecret); err != nil { | ||
log.Error(err, "failed to update object store owner reference", "cluster", key.Name) | ||
err = fmt.Errorf("error updating owner reference for secret in cluster %s: %w", key.Name, err) | ||
return nil, ctrl.Result{}, err | ||
} | ||
} | ||
|
@@ -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{}) | ||
if err != nil { | ||
if apierrors.IsNotFound(err) { | ||
// Namespace does not exist, create it | ||
ns := &corev1.Namespace{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: namespace, | ||
}, | ||
} | ||
_, err := kubeClient.CoreV1().Namespaces().Create(context.TODO(), ns, metav1.CreateOptions{}) | ||
if err != nil { | ||
return fmt.Errorf("failed to create namespace %s: %w", namespace, err) | ||
} | ||
} else { | ||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. duplicate creating secret, though you have checked alkready exists |
||
return err | ||
return fmt.Errorf("failed to create secret in namespace %s: %w", namespace, err) | ||
} | ||
|
||
return nil | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: reuse karmadautil.EnsureNamespaceExist