@@ -17,7 +17,10 @@ limitations under the License.
1717package v1beta1
1818
1919import (
20+ "regexp"
21+
2022 condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
23+ "github.com/openstack-k8s-operators/lib-common/modules/common/util"
2124 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2225)
2326
@@ -205,3 +208,42 @@ func init() {
205208func (instance OpenStackVersion ) IsReady () bool {
206209 return instance .Status .Conditions .IsTrue (condition .ReadyCondition )
207210}
211+
212+ func getOpenStackReleaseVersion (openstackReleaseVersion string , releaseVersionScheme string , operatorConditionName string ) string {
213+
214+ /* NOTE: dprince
215+ * The releaseVersionScheme can be optionally used to enable 'csvEpochAppend' behavior
216+ * This is used by some downstream builds to append the version to the CSV version suffix (epoch) which
217+ * is obtained from the OPERATOR_CONDITION_NAME environment variable to the openstack release version.
218+ * In some downstream build systems CSV version bumps can be easily automated where as the
219+ * OPENSTACK_RELEASE_VERSION is more of a static constant.
220+ * The reason we don't always use the CSV version is that the raw version in those same downstream
221+ * builds does not match the OpenStackVersion (for example CSV version is 1.0 where as OpenStack product
222+ * version is set to 18.0, go figure!)
223+ */
224+ if releaseVersionScheme == "csvEpochAppend" {
225+ re := regexp .MustCompile (`\.[[:digit:]]{10,}\.p` )
226+ operatorConditionEpoch := re .FindString (operatorConditionName )
227+ if operatorConditionEpoch == "" {
228+ return openstackReleaseVersion
229+ } else {
230+ return openstackReleaseVersion + operatorConditionEpoch
231+ }
232+ }
233+ return openstackReleaseVersion
234+ }
235+
236+ // GetOpenStackReleaseVersion - returns the OpenStack release version
237+ func GetOpenStackReleaseVersion (envVars []string ) string {
238+
239+ return getOpenStackReleaseVersion (
240+ util .GetEnvVar ("OPENSTACK_RELEASE_VERSION" , "" ),
241+ // can be set to csvEpochAppend
242+ util .GetEnvVar ("OPENSTACK_RELEASE_VERSION_SCHEME" , "" ),
243+ // NOTE: dprince this is essentially the CSV version. OLM sets this to provide
244+ // a way for the controller-manager to know the operator condition name
245+ // we do it this way to *avoid requiring the CSV structs in this operator*
246+ util .GetEnvVar ("OPERATOR_CONDITION_NAME" , "" ),
247+ )
248+
249+ }
0 commit comments