github.com/IBM-Blockchain/fabric-operator@v1.0.4/controllers/ibpca/predicate.go (about) 1 /* 2 * Copyright contributors to the Hyperledger Fabric Operator project 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 package ibpca 20 21 import ( 22 "reflect" 23 24 current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1" 25 ) 26 27 // Update defines a list of elements that we detect spec updates on 28 type Update struct { 29 specUpdated bool 30 caOverridesUpdated bool 31 tlscaOverridesUpdated bool 32 restartNeeded bool 33 caCryptoUpdated bool 34 caCryptoCreated bool 35 renewTLSCert bool 36 imagesUpdated bool 37 fabricVersionUpdated bool 38 caTagUpdated bool 39 // update GetUpdateStackWithTrues when new fields are added 40 } 41 42 // SpecUpdated returns true if any fields in spec are updated 43 func (u *Update) SpecUpdated() bool { 44 return u.specUpdated 45 } 46 47 // CAOverridesUpdated returns true if ca config overrides updated 48 func (u *Update) CAOverridesUpdated() bool { 49 return u.caOverridesUpdated 50 } 51 52 // TLSCAOverridesUpdated returns true if TLS ca config overrides updated 53 func (u *Update) TLSCAOverridesUpdated() bool { 54 return u.tlscaOverridesUpdated 55 } 56 57 // ConfigOverridesUpdated returns true if either ca or TLS ca overrides updated 58 func (u *Update) ConfigOverridesUpdated() bool { 59 return u.caOverridesUpdated || u.tlscaOverridesUpdated 60 } 61 62 // RestartNeeded returns true if changes in spec require components to restart 63 func (u *Update) RestartNeeded() bool { 64 return u.restartNeeded 65 } 66 67 // CACryptoUpdated returns true if crypto material updated 68 func (u *Update) CACryptoUpdated() bool { 69 return u.caCryptoUpdated 70 } 71 72 // CACryptoCreated returns true if crypto material created 73 func (u *Update) CACryptoCreated() bool { 74 return u.caCryptoCreated 75 } 76 77 // RenewTLSCert returns true if need to renew TLS cert 78 func (u *Update) RenewTLSCert() bool { 79 return u.renewTLSCert 80 } 81 82 // ImagesUpdated returns true if images updated 83 func (u *Update) ImagesUpdated() bool { 84 return u.imagesUpdated 85 } 86 87 // FabricVersionUpdated returns true if fabric version updated 88 func (u *Update) FabricVersionUpdated() bool { 89 return u.fabricVersionUpdated 90 } 91 92 func (u *Update) CATagUpdated() bool { 93 return u.caTagUpdated 94 } 95 96 // GetUpdateStackWithTrues is a helper method to print updates that have been detected 97 func (u *Update) GetUpdateStackWithTrues() string { 98 stack := "" 99 100 if u.specUpdated { 101 stack += "specUpdated " 102 } 103 if u.caOverridesUpdated { 104 stack += "caOverridesUpdated " 105 } 106 if u.tlscaOverridesUpdated { 107 stack += "tlscaOverridesUpdated " 108 } 109 if u.restartNeeded { 110 stack += "restartNeeded " 111 } 112 if u.caCryptoUpdated { 113 stack += "caCryptoUpdated " 114 } 115 if u.caCryptoCreated { 116 stack += "caCryptoCreated " 117 } 118 if u.renewTLSCert { 119 stack += "renewTLSCert " 120 } 121 if u.imagesUpdated { 122 stack += "imagesUpdated " 123 } 124 if u.fabricVersionUpdated { 125 stack += "fabricVersionUpdated " 126 } 127 if u.caTagUpdated { 128 stack += "caTagUpdated " 129 } 130 131 if len(stack) == 0 { 132 stack = "emptystack " 133 } 134 135 return stack 136 } 137 138 func imagesUpdated(old, new *current.IBPCA) bool { 139 if new.Spec.Images != nil { 140 if old.Spec.Images == nil { 141 return true 142 } 143 144 if old.Spec.Images != nil { 145 return !reflect.DeepEqual(old.Spec.Images, new.Spec.Images) 146 } 147 } 148 149 return false 150 } 151 152 func fabricVersionUpdated(old, new *current.IBPCA) bool { 153 return old.Spec.FabricVersion != new.Spec.FabricVersion 154 }