util.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. Copyright © 2025 ESO Maintainer Team
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. https://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package clusterpushsecret
  14. import (
  15. v1 "k8s.io/api/core/v1"
  16. "github.com/external-secrets/external-secrets/apis/externalsecrets/v1alpha1"
  17. "github.com/external-secrets/external-secrets/pkg/controllers/clusterpushsecret/cpsmetrics"
  18. )
  19. func NewClusterPushSecretCondition(failedNamespaces map[string]error) *v1alpha1.PushSecretStatusCondition {
  20. if len(failedNamespaces) == 0 {
  21. return &v1alpha1.PushSecretStatusCondition{
  22. Type: v1alpha1.PushSecretReady,
  23. Status: v1.ConditionTrue,
  24. }
  25. }
  26. condition := &v1alpha1.PushSecretStatusCondition{
  27. Type: v1alpha1.PushSecretReady,
  28. Status: v1.ConditionFalse,
  29. Message: errNamespacesFailed,
  30. }
  31. return condition
  32. }
  33. func SetClusterPushSecretCondition(ces *v1alpha1.ClusterPushSecret, condition v1alpha1.PushSecretStatusCondition) {
  34. ces.Status.Conditions = append(filterOutCondition(ces.Status.Conditions, condition.Type), condition)
  35. cpsmetrics.UpdateClusterPushSecretCondition(ces, &condition)
  36. }
  37. // filterOutCondition returns an empty set of conditions with the provided type.
  38. func filterOutCondition(conditions []v1alpha1.PushSecretStatusCondition, condType v1alpha1.PushSecretConditionType) []v1alpha1.PushSecretStatusCondition {
  39. newConditions := make([]v1alpha1.PushSecretStatusCondition, 0, len(conditions))
  40. for _, c := range conditions {
  41. if c.Type == condType {
  42. continue
  43. }
  44. newConditions = append(newConditions, c)
  45. }
  46. return newConditions
  47. }