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(KONFLUX-3854): Cleanup MPC secrets as well if any #1287

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
29 changes: 28 additions & 1 deletion pkg/clients/common/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/labels"
)

// Creates a new secret in a specified namespace
Expand All @@ -25,11 +26,37 @@ func (s *SuiteController) GetSecret(ns string, name string) (*corev1.Secret, err
return s.KubeInterface().CoreV1().Secrets(ns).Get(context.Background(), name, metav1.GetOptions{})
}

// Deleted a secret in a specified namespace
// Delete a secret in a specified namespace
func (s *SuiteController) DeleteSecret(ns string, name string) error {
return s.KubeInterface().CoreV1().Secrets(ns).Delete(context.Background(), name, metav1.DeleteOptions{})
}

// ListSecrets return a list of secrets from a namespace by label and selection limits
func (s *SuiteController) ListSecrets(ns string, labelKey string, labelValue string, selectionLimit int64) (*corev1.SecretList, error) {
labelSelector := metav1.LabelSelector{MatchLabels: map[string]string{labelKey: labelValue}}
listOptions := metav1.ListOptions{
LabelSelector: labels.Set(labelSelector.MatchLabels).String(),
Limit: selectionLimit,
}
return s.KubeInterface().CoreV1().Secrets(ns).List(context.Background(), listOptions)
}

// Delete all secrets in a specified namespace matching to label
func (s *SuiteController) DeleteSecretsByLabel(ns string, labelKey string, labelValue string) error {
secretList, err := s.ListSecrets(ns, labelKey, labelValue, 1024)
if err != nil {
return err
}

for _, secret := range secretList.Items {
jhutar marked this conversation as resolved.
Show resolved Hide resolved
err = s.DeleteSecret(ns, secret.Name)
if err != nil {
return err
}
}
return nil
}

// Links a secret to a specified serviceaccount, if argument addImagePullSecrets is true secret will be added also to ImagePullSecrets of SA.
func (s *SuiteController) LinkSecretToServiceAccount(ns, secret, serviceaccount string, addImagePullSecrets bool) error {
timeout := 20 * time.Second
Expand Down
5 changes: 5 additions & 0 deletions tests/load-tests/pkg/journey/handle_purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func purgeStage(f *framework.Framework, namespace string) error {
return fmt.Errorf("Error when deleting pipeline runs in namespace %s: %v", namespace, err)
}

err = f.AsKubeDeveloper.CommonController.DeleteSecretsByLabel(namespace, "build.appstudio.redhat.com/multi-platform-secret", "true")
if err != nil {
return fmt.Errorf("Error when deleting MPC secrets in namespace %s: %v", namespace, err)
}

logging.Logger.Debug("Finished purging namespace %s", namespace)
return nil
}
Expand Down
Loading