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

Fix delete secret #73

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hack/benchmark/benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function generate_data {
}

function create_secrets {
cat /dev/stdin | jq -r --argjson t "$(<$_secret_template_path)" '.[] as $id | $t | .metadata.name=$id | .metadata.labels["kyma-project.io/runtime-id"]=$id'
cat /dev/stdin | jq -r --argjson t "$(<$_secret_template_path)" '.[] as $id | $t | .metadata.name="kubeconfig-"+$id | .metadata.labels["kyma-project.io/runtime-id"]=$id | .metadata.labels["kyma-project.io/shoot-name"]=$id'
}

datetime_postfix=$(date -u +%Y-%m-%dT%H:%M:%S)
Expand Down
11 changes: 9 additions & 2 deletions hack/benchmark/secret.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
"kind": "Secret",
"metadata": {
"labels": {
"kyma-project.io/runtime-id": "01a5af79-b073-48a1-906d-26c15933b12a",
"kyma-project.io/shoot-name": "benchmark-invalid"
"kyma-project.io/runtime-id": "01a5af79-b073-48a1-906d-26c15933b12a",
"kyma-project.io/shoot-name": "benchmark-invalid",
"kyma-project.io/instance-id": "test",
"kyma-project.io/broker-plan-id": "test",
"kyma-project.io/broker-plan-name": "test",
"kyma-project.io/global-account-id": "test",
"kyma-project.io/subaccount-id": "test",
"kyma-project.io/region": "test",
"operator.kyma-project.io/kyma-name": "test"
},
"name": "kubeconfig-01a5af79-b073-48a1-906d-26c15933b12a",
"namespace": "kcp-system"
Expand Down
16 changes: 11 additions & 5 deletions internal/controller/gardener_cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (controller *GardenerClusterController) resultWithoutRequeue() ctrl.Result
}

func (controller *GardenerClusterController) persistStatusChange(ctx context.Context, cluster *imv1.GardenerCluster) error {
err := controller.Client.Status().Update(ctx, cluster)
err := controller.Status().Update(ctx, cluster)
if err != nil {
controller.log.Error(err, "status update failed")
}
Expand All @@ -157,16 +157,22 @@ func (controller *GardenerClusterController) deleteKubeconfigSecret(ctx context.
})

var secretList corev1.SecretList
err := controller.Client.List(ctx, &secretList, selector)
if err != nil {
err := controller.List(ctx, &secretList, selector)

if err != nil && !k8serrors.IsNotFound(err) {
return err
}

if len(secretList.Items) != 1 {
// secret was already deleted, nothing to do
if len(secretList.Items) < 1 {
return nil
}

if len(secretList.Items) > 1 {
return errors.Errorf("unexpected numer of secrets found for cluster CR `%s`", clusterCRName)
}

return controller.Client.Delete(ctx, &secretList.Items[0])
return controller.Delete(ctx, &secretList.Items[0])
}

func (controller *GardenerClusterController) getSecret(shootName string) (*corev1.Secret, error) {
Expand Down
Loading