k8s.io/kubernetes@v1.29.3/pkg/controller/certificates/certificate_controller_utils.go (about) 1 /* 2 Copyright 2016 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 package certificates 18 19 import ( 20 certificates "k8s.io/api/certificates/v1" 21 v1 "k8s.io/api/core/v1" 22 ) 23 24 // IsCertificateRequestApproved returns true if a certificate request has the 25 // "Approved" condition and no "Denied" conditions; false otherwise. 26 func IsCertificateRequestApproved(csr *certificates.CertificateSigningRequest) bool { 27 approved, denied := GetCertApprovalCondition(&csr.Status) 28 return approved && !denied 29 } 30 31 // HasTrueCondition returns true if the csr contains a condition of the specified type with a status that is set to True or is empty 32 func HasTrueCondition(csr *certificates.CertificateSigningRequest, conditionType certificates.RequestConditionType) bool { 33 for _, c := range csr.Status.Conditions { 34 if c.Type == conditionType && (len(c.Status) == 0 || c.Status == v1.ConditionTrue) { 35 return true 36 } 37 } 38 return false 39 } 40 41 func GetCertApprovalCondition(status *certificates.CertificateSigningRequestStatus) (approved bool, denied bool) { 42 for _, c := range status.Conditions { 43 if c.Type == certificates.CertificateApproved { 44 approved = true 45 } 46 if c.Type == certificates.CertificateDenied { 47 denied = true 48 } 49 } 50 return 51 }