github.com/IBM-Blockchain/fabric-operator@v1.0.4/version/fabricversion.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 version 20 21 import ( 22 "strings" 23 ) 24 25 const ( 26 // Fabric versions 27 V1 = "1" 28 V1_0_0 = "1.0.0" 29 V1_4_0 = "1.4.0" 30 V1_4_6 = "1.4.6" 31 V1_4_7 = "1.4.7" 32 V1_4_8 = "1.4.8" 33 V1_4_9 = "1.4.9" 34 V1_5_3 = "1.5.3" 35 V2 = "2" 36 V2_0_0 = "2.0.0" 37 V2_0_1 = "2.0.1" 38 V2_1_0 = "2.1.0" 39 V2_1_1 = "2.1.1" 40 V2_2_0 = "2.2.0" 41 V2_2_1 = "2.2.1" 42 V2_2_3 = "2.2.3" 43 V2_2_4 = "2.2.4" 44 V2_2_5 = "2.2.5" 45 46 V2_4_1 = "2.4.1" 47 48 V1_4 = "V1.4" 49 50 Unsupported = "unsupported" 51 ) 52 53 // OldFabricVersionsLookup map contains old fabric versions keyed 54 // by image tag. Used to set the fabric version of migrated instances 55 // that don't have fabric version set in their specs. 56 // This should not contain newer fabric versions as instances with newer 57 // fabric versions should have fabric version set in their spec. 58 var OldFabricVersionsLookup = map[string]interface{}{ 59 "1.4.2": nil, 60 "1.4.3": nil, 61 "1.4.4": nil, 62 "1.4.5": nil, 63 "1.4.6": nil, 64 "V1.4": nil, 65 "unsupported": nil, 66 } 67 68 // GetFabricVersionFrom extracts fabric version from image tag in the format: <version>-<releasedate>-<arch> 69 func GetFabricVersionFrom(imageTag string) string { 70 tagItems := strings.Split(imageTag, "-") 71 if len(tagItems) != 3 { 72 // Newer tags use sha256 digests, from which 73 // versions cannot be extracted. 74 return "" 75 } 76 77 fabVersion := tagItems[0] 78 return fabVersion 79 } 80 81 // GetOldFabricVersionFrom is only to be used when we need to find the 82 // fabric version of a migrated instance where instance.Spec.FabricVersion 83 // was not set previously. 84 func GetOldFabricVersionFrom(imageTag string) string { 85 version := GetFabricVersionFrom(imageTag) 86 87 _, found := OldFabricVersionsLookup[version] 88 if !found { 89 return Unsupported 90 } 91 92 return version 93 } 94 95 // IsMigratedFabricVersion returns true if the given fabric version 96 // was set during migration to 2.5.2 or above 97 func IsMigratedFabricVersion(fabricVersion string) bool { 98 _, found := OldFabricVersionsLookup[fabricVersion] 99 return found 100 }