k8s.io/kubernetes@v1.29.3/pkg/controller/replication/replication_controller_utils.go (about) 1 /* 2 Copyright 2015 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 // If you make changes to this file, you should also make the corresponding change in ReplicaSet. 18 19 package replication 20 21 import ( 22 "k8s.io/api/core/v1" 23 ) 24 25 // GetCondition returns a replication controller condition with the provided type if it exists. 26 func GetCondition(status v1.ReplicationControllerStatus, condType v1.ReplicationControllerConditionType) *v1.ReplicationControllerCondition { 27 for i := range status.Conditions { 28 c := status.Conditions[i] 29 if c.Type == condType { 30 return &c 31 } 32 } 33 return nil 34 } 35 36 // SetCondition adds/replaces the given condition in the replication controller status. 37 func SetCondition(status *v1.ReplicationControllerStatus, condition v1.ReplicationControllerCondition) { 38 currentCond := GetCondition(*status, condition.Type) 39 if currentCond != nil && currentCond.Status == condition.Status && currentCond.Reason == condition.Reason { 40 return 41 } 42 newConditions := filterOutCondition(status.Conditions, condition.Type) 43 status.Conditions = append(newConditions, condition) 44 } 45 46 // RemoveCondition removes the condition with the provided type from the replication controller status. 47 func RemoveCondition(status *v1.ReplicationControllerStatus, condType v1.ReplicationControllerConditionType) { 48 status.Conditions = filterOutCondition(status.Conditions, condType) 49 } 50 51 // filterOutCondition returns a new slice of replication controller conditions without conditions with the provided type. 52 func filterOutCondition(conditions []v1.ReplicationControllerCondition, condType v1.ReplicationControllerConditionType) []v1.ReplicationControllerCondition { 53 var newConditions []v1.ReplicationControllerCondition 54 for _, c := range conditions { 55 if c.Type == condType { 56 continue 57 } 58 newConditions = append(newConditions, c) 59 } 60 return newConditions 61 }