github.com/verrazzano/verrazzano@v1.7.0/platform-operator/controllers/common/controller_utils.go (about) 1 // Copyright (c) 2023, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package common 5 6 import ( 7 "fmt" 8 9 "github.com/verrazzano/verrazzano/pkg/semver" 10 vzapi "github.com/verrazzano/verrazzano/platform-operator/apis/verrazzano/v1alpha1" 11 "github.com/verrazzano/verrazzano/platform-operator/apis/verrazzano/validators" 12 ) 13 14 // IsUpgradeRequired Returns true if the BOM version is greather than CR spec or status version 15 func IsUpgradeRequired(actualCR *vzapi.Verrazzano) (bool, error) { 16 if actualCR == nil { 17 return false, fmt.Errorf("no Verrazzano CR provided") 18 } 19 bomVersion, err := validators.GetCurrentBomVersion() 20 if err != nil { 21 return false, err 22 } 23 24 if len(actualCR.Spec.Version) > 0 { 25 specVersion, err := semver.NewSemVersion(actualCR.Spec.Version) 26 if err != nil { 27 return false, err 28 } 29 return bomVersion.IsGreatherThan(specVersion), nil 30 } 31 if len(actualCR.Status.Version) > 0 { 32 statusVersion, err := semver.NewSemVersion(actualCR.Status.Version) 33 if err != nil { 34 return false, err 35 } 36 return bomVersion.IsGreatherThan(statusVersion), nil 37 } 38 return false, nil 39 }