github.com/IBM-Blockchain/fabric-operator@v1.0.4/controllers/ibppeer/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 ibppeer 20 21 import ( 22 "reflect" 23 24 current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1" 25 commoninit "github.com/IBM-Blockchain/fabric-operator/pkg/initializer/common" 26 ) 27 28 type Update struct { 29 specUpdated bool 30 overridesUpdated bool 31 dindArgsUpdated bool 32 tlsCertUpdated bool 33 ecertUpdated bool 34 peerTagUpdated bool 35 restartNeeded bool 36 ecertReenrollNeeded bool 37 tlsReenrollNeeded bool 38 ecertNewKeyReenroll bool 39 tlscertNewKeyReenroll bool 40 migrateToV2 bool 41 migrateToV24 bool 42 mspUpdated bool 43 ecertEnroll bool 44 tlscertEnroll bool 45 upgradedbs bool 46 tlsCertCreated bool 47 ecertCreated bool 48 nodeOUUpdated bool 49 imagesUpdated bool 50 fabricVersionUpdated bool 51 // update GetUpdateStackWithTrues when new fields are added 52 } 53 54 func (u *Update) SpecUpdated() bool { 55 return u.specUpdated 56 } 57 58 func (u *Update) ConfigOverridesUpdated() bool { 59 return u.overridesUpdated 60 } 61 62 func (u *Update) DindArgsUpdated() bool { 63 return u.dindArgsUpdated 64 } 65 66 func (u *Update) TLSCertUpdated() bool { 67 return u.tlsCertUpdated 68 } 69 70 func (u *Update) EcertUpdated() bool { 71 return u.ecertUpdated 72 } 73 74 func (u *Update) PeerTagUpdated() bool { 75 return u.peerTagUpdated 76 } 77 78 func (u *Update) CertificateUpdated() bool { 79 return u.tlsCertUpdated || u.ecertUpdated 80 } 81 82 func (u *Update) GetUpdatedCertType() commoninit.SecretType { 83 if u.tlsCertUpdated { 84 return commoninit.TLS 85 } else if u.ecertUpdated { 86 return commoninit.ECERT 87 } 88 return "" 89 } 90 91 func (u *Update) RestartNeeded() bool { 92 return u.restartNeeded 93 } 94 95 func (u *Update) EcertReenrollNeeded() bool { 96 return u.ecertReenrollNeeded 97 } 98 99 func (u *Update) TLSReenrollNeeded() bool { 100 return u.tlsReenrollNeeded 101 } 102 103 func (u *Update) EcertNewKeyReenroll() bool { 104 return u.ecertNewKeyReenroll 105 } 106 107 func (u *Update) TLScertNewKeyReenroll() bool { 108 return u.tlscertNewKeyReenroll 109 } 110 111 func (u *Update) MigrateToV2() bool { 112 return u.migrateToV2 113 } 114 115 func (u *Update) MigrateToV24() bool { 116 return u.migrateToV24 117 } 118 119 func (u *Update) UpgradeDBs() bool { 120 return u.upgradedbs 121 } 122 123 func (u *Update) EcertEnroll() bool { 124 return u.ecertEnroll 125 } 126 127 func (u *Update) TLSCertEnroll() bool { 128 return u.tlscertEnroll 129 } 130 131 func (u *Update) SetDindArgsUpdated(updated bool) { 132 u.dindArgsUpdated = updated 133 } 134 135 func (u *Update) MSPUpdated() bool { 136 return u.mspUpdated 137 } 138 139 func (u *Update) TLSCertCreated() bool { 140 return u.tlsCertCreated 141 } 142 143 func (u *Update) EcertCreated() bool { 144 return u.ecertCreated 145 } 146 147 func (u *Update) CertificateCreated() bool { 148 return u.tlsCertCreated || u.ecertCreated 149 } 150 151 func (u *Update) GetCreatedCertType() commoninit.SecretType { 152 if u.tlsCertCreated { 153 return commoninit.TLS 154 } else if u.ecertCreated { 155 return commoninit.ECERT 156 } 157 return "" 158 } 159 160 func (u *Update) CryptoBackupNeeded() bool { 161 return u.ecertEnroll || 162 u.tlscertEnroll || 163 u.ecertReenrollNeeded || 164 u.tlsReenrollNeeded || 165 u.ecertNewKeyReenroll || 166 u.tlscertNewKeyReenroll || 167 u.mspUpdated 168 } 169 170 func (u *Update) NodeOUUpdated() bool { 171 return u.nodeOUUpdated 172 } 173 174 // ImagesUpdated returns true if images updated 175 func (u *Update) ImagesUpdated() bool { 176 return u.imagesUpdated 177 } 178 179 // FabricVersionUpdated returns true if fabric version updated 180 func (u *Update) FabricVersionUpdated() bool { 181 return u.fabricVersionUpdated 182 } 183 184 func (u *Update) Needed() bool { 185 return u.specUpdated || 186 u.overridesUpdated || 187 u.dindArgsUpdated || 188 u.tlsCertUpdated || 189 u.ecertUpdated || 190 u.peerTagUpdated || 191 u.restartNeeded || 192 u.ecertReenrollNeeded || 193 u.tlsReenrollNeeded || 194 u.ecertNewKeyReenroll || 195 u.tlscertNewKeyReenroll || 196 u.migrateToV2 || 197 u.migrateToV24 || 198 u.mspUpdated || 199 u.ecertEnroll || 200 u.upgradedbs || 201 u.nodeOUUpdated || 202 u.imagesUpdated || 203 u.fabricVersionUpdated 204 } 205 206 func (u *Update) GetUpdateStackWithTrues() string { 207 stack := "" 208 209 if u.specUpdated { 210 stack += "specUpdated " 211 } 212 if u.overridesUpdated { 213 stack += "overridesUpdated " 214 } 215 if u.dindArgsUpdated { 216 stack += "dindArgsUpdated " 217 } 218 if u.tlsCertUpdated { 219 stack += "tlsCertUpdated " 220 } 221 if u.ecertUpdated { 222 stack += "ecertUpdated " 223 } 224 if u.peerTagUpdated { 225 stack += "peerTagUpdated " 226 } 227 if u.restartNeeded { 228 stack += "restartNeeded " 229 } 230 if u.ecertReenrollNeeded { 231 stack += "ecertReenrollNeeded" 232 } 233 if u.tlsReenrollNeeded { 234 stack += "tlsReenrollNeeded" 235 } 236 if u.migrateToV2 { 237 stack += "migrateToV2 " 238 } 239 if u.migrateToV24 { 240 stack += "migrateToV24 " 241 } 242 if u.mspUpdated { 243 stack += "mspUpdated " 244 } 245 if u.ecertEnroll { 246 stack += "ecertEnroll " 247 } 248 if u.tlscertEnroll { 249 stack += "tlscertEnroll " 250 } 251 if u.upgradedbs { 252 stack += "upgradedbs " 253 } 254 if u.tlsCertCreated { 255 stack += "tlsCertCreated " 256 } 257 if u.ecertCreated { 258 stack += "ecertCreated " 259 } 260 if u.nodeOUUpdated { 261 stack += "nodeOUUpdated " 262 } 263 if u.imagesUpdated { 264 stack += "imagesUpdated " 265 } 266 if u.fabricVersionUpdated { 267 stack += "fabricVersionUpdated " 268 } 269 270 if len(stack) == 0 { 271 stack = "emptystack " 272 } 273 274 return stack 275 } 276 277 func imagesUpdated(old, new *current.IBPPeer) bool { 278 if new.Spec.Images != nil { 279 if old.Spec.Images == nil { 280 return true 281 } 282 283 if old.Spec.Images != nil { 284 return !reflect.DeepEqual(old.Spec.Images, new.Spec.Images) 285 } 286 } 287 288 return false 289 } 290 291 func fabricVersionUpdated(old, new *current.IBPPeer) bool { 292 return old.Spec.FabricVersion != new.Spec.FabricVersion 293 }