Skip to content

Commit

Permalink
Merge pull request #1355 from FabianKramm/main
Browse files Browse the repository at this point in the history
fix: delete sa token if already exists
  • Loading branch information
FabianKramm authored Nov 15, 2023
2 parents 2cb24f4 + a4f258b commit 1f8d1bc
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pkg/controllers/resources/pods/translate/sa_token_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,20 @@ func SATokenSecret(ctx context.Context, pClient client.Client, vPod *corev1.Pod,
existingSecret, err := GetSecretIfExists(ctx, pClient, vPod.Name, vPod.Namespace)
if err != nil {
return err
} else if existingSecret == nil {
}

// check if we need to delete the secret
if existingSecret != nil {
err = pClient.Delete(ctx, existingSecret)
if err != nil && !kerrors.IsNotFound(err) {
return err
}

existingSecret = nil
}

// secret does not exist we need to create it
if existingSecret == nil {
// create to secret with the given token
secret := &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -84,10 +97,8 @@ func SetPodAsOwner(ctx context.Context, pPod *corev1.Pod, pClient client.Client,
}

owners := secret.GetOwnerReferences()

if translate.Owner != nil {
// check if the current owner is the vcluster service

for i, owner := range owners {
if owner.UID == translate.Owner.GetUID() {
// path this with current pod as owner instead
Expand Down

0 comments on commit 1f8d1bc

Please sign in to comment.