util.go 1.9 KB

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