Skip to content

Commit

Permalink
pkg/upgrade: convert RemoveLabel to Action
Browse files Browse the repository at this point in the history
Signed-off-by: Yauheni Kaliuta <[email protected]>
  • Loading branch information
ykaliuta committed Apr 26, 2024
1 parent 3e2f205 commit fe4c4ac
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,18 +414,12 @@ func deleteResource(cli client.Client, namespace string, resourceType string) er
}

func RemoveLabel(cli client.Client, objectName string, labelKey string) error {
foundNamespace := &corev1.Namespace{}
if err := cli.Get(context.TODO(), client.ObjectKey{Name: objectName}, foundNamespace); err != nil {
if apierrs.IsNotFound(err) {
return nil
}
return fmt.Errorf("could not get %s namespace: %w", objectName, err)
}
delete(foundNamespace.Labels, labelKey)
if err := cli.Update(context.TODO(), foundNamespace); err != nil {
return fmt.Errorf("error removing %s from %s : %w", labelKey, objectName, err)
}
return nil
return action.NewDeleteLabel(cli, labelKey).
Exec(context.TODO(), action.ResourceSpec{
Gvk: gvk.Namespace,
Path: []string{"metadata", "name"},
Values: []string{objectName},
})
}

func deleteDeprecatedNamespace(ctx context.Context, cli client.Client, namespace string) error {
Expand Down

0 comments on commit fe4c4ac

Please sign in to comment.