Skip to content

Commit

Permalink
when sercret was found need break the loop
Browse files Browse the repository at this point in the history
use rmSecretNames.Has instead of loop

use rmSecretNames.Has instead of loop
  • Loading branch information
guangxuli committed Aug 23, 2016
1 parent a1c9eb1 commit d52ba0c
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions pkg/cmd/cli/secrets/unlink_secret_from_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,33 +82,18 @@ func (o UnlinkSecretOptions) unlinkSecretsFromServiceAccount(serviceaccount *kap
newPullSecrets := []kapi.LocalObjectReference{}

// Check the mount secrets
for i := len(serviceaccount.Secrets) - 1; i >= 0; i-- {
found := false
for _, secretname := range rmSecretNames.List() {
if secretname == serviceaccount.Secrets[i].Name {
found = true
// Skip adding this to the updated list
}
}

if !found {
for _, secret := range serviceaccount.Secrets {
if !rmSecretNames.Has(secret.Name) {
// Copy this back in, since it doesn't match the ones we're removing
newMountSecrets = append(newMountSecrets, serviceaccount.Secrets[i])
newMountSecrets = append(newMountSecrets, secret)
}
}

// Check the image pull secrets
for i := len(serviceaccount.ImagePullSecrets) - 1; i >= 0; i-- {
found := false
for _, secretname := range rmSecretNames.List() {
if secretname == serviceaccount.ImagePullSecrets[i].Name {
found = true
// Skip adding this to the updated list
}
}
if !found {
for _, imagePullSecret := range serviceaccount.ImagePullSecrets {
if !rmSecretNames.Has(imagePullSecret.Name) {
// Copy this back in, since it doesn't match the one we're removing
newPullSecrets = append(newPullSecrets, serviceaccount.ImagePullSecrets[i])
newPullSecrets = append(newPullSecrets, imagePullSecret)
}
}

Expand Down

0 comments on commit d52ba0c

Please sign in to comment.