Skip to content

Commit 5656b32

Browse files
committed
OpenStackVersion: Add releaseVersionScheme and csvVersionAppend support
The releaseVersionScheme can be optionally used to enable 'csvEpochAppend' behavior This is used by some downstream builds to append the version to the CSV version suffix (epoch) which is obtained from the OPERATOR_CONDITION_NAME environment variable to the openstack release version. In some downstream build systems CSV version bumps can be easily automated where as the OPENSTACK_RELEASE_VERSION is more of a static constant. Co-authored-by: Miguel Garcia(mgarciac@redhat.com) Jira: OSPRH-9568
1 parent 19b20d7 commit 5656b32

3 files changed

Lines changed: 45 additions & 2 deletions

File tree

‎apis/core/v1beta1/openstackversion_types.go‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
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() {
205208
func (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+
}

‎apis/core/v1beta1/openstackversion_webhook.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ package v1beta1
1818

1919
import (
2020
"context"
21+
"os"
2122

2223
apierrors "k8s.io/apimachinery/pkg/api/errors"
2324
"k8s.io/apimachinery/pkg/runtime/schema"
2425
"k8s.io/apimachinery/pkg/util/validation/field"
2526

26-
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
2727
"k8s.io/apimachinery/pkg/runtime"
2828
ctrl "sigs.k8s.io/controller-runtime"
2929
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -173,7 +173,7 @@ func (r *OpenStackVersion) ValidateDelete() (admission.Warnings, error) {
173173
// SetupVersionDefaults -
174174
func SetupVersionDefaults() {
175175
openstackVersionDefaults := OpenStackVersionDefaults{
176-
AvailableVersion: util.GetEnvVar("OPENSTACK_RELEASE_VERSION", ""),
176+
AvailableVersion: GetOpenStackReleaseVersion(os.Environ()),
177177
}
178178

179179
SetupOpenStackVersionDefaults(openstackVersionDefaults)

‎controllers/core/openstackversion_controller.go‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func SetupVersionDefaults() {
5656
localVars[envArr[0]] = &envArr[1]
5757
}
5858
}
59+
envAvailableVersion = corev1beta1.GetOpenStackReleaseVersion(os.Environ())
5960
envContainerImages = localVars
6061
}
6162

0 commit comments

Comments
 (0)