util.go 2.0 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 clusterexternalsecret
  14. import (
  15. v1 "k8s.io/api/core/v1"
  16. esv1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
  17. "github.com/external-secrets/external-secrets/pkg/controllers/clusterexternalsecret/cesmetrics"
  18. )
  19. func NewClusterExternalSecretCondition(failedNamespaces map[string]error) *esv1.ClusterExternalSecretStatusCondition {
  20. if len(failedNamespaces) == 0 {
  21. return &esv1.ClusterExternalSecretStatusCondition{
  22. Type: esv1.ClusterExternalSecretReady,
  23. Status: v1.ConditionTrue,
  24. }
  25. }
  26. condition := &esv1.ClusterExternalSecretStatusCondition{
  27. Type: esv1.ClusterExternalSecretReady,
  28. Status: v1.ConditionFalse,
  29. Message: errNamespacesFailed,
  30. }
  31. return condition
  32. }
  33. func SetClusterExternalSecretCondition(ces *esv1.ClusterExternalSecret, condition esv1.ClusterExternalSecretStatusCondition) {
  34. ces.Status.Conditions = append(filterOutCondition(ces.Status.Conditions, condition.Type), condition)
  35. cesmetrics.UpdateClusterExternalSecretCondition(ces, &condition)
  36. }
  37. // filterOutCondition returns an empty set of conditions with the provided type.
  38. func filterOutCondition(conditions []esv1.ClusterExternalSecretStatusCondition, condType esv1.ClusterExternalSecretConditionType) []esv1.ClusterExternalSecretStatusCondition {
  39. newConditions := make([]esv1.ClusterExternalSecretStatusCondition, 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. }