Skip to content

Commit

Permalink
OpenStackVersion: Add releaseVersionScheme and csvVersionAppend support
Browse files Browse the repository at this point in the history
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([email protected])

Jira: OSPRH-9568
  • Loading branch information
dprince committed Sep 18, 2024
1 parent 19b20d7 commit 5656b32
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
42 changes: 42 additions & 0 deletions apis/core/v1beta1/openstackversion_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ limitations under the License.
package v1beta1

import (
"regexp"

condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -205,3 +208,42 @@ func init() {
func (instance OpenStackVersion) IsReady() bool {
return instance.Status.Conditions.IsTrue(condition.ReadyCondition)
}

func getOpenStackReleaseVersion(openstackReleaseVersion string, releaseVersionScheme string, operatorConditionName string) string {

/* NOTE: dprince
* 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.
* The reason we don't always use the CSV version is that the raw version in those same downstream
* builds does not match the OpenStackVersion (for example CSV version is 1.0 where as OpenStack product
* version is set to 18.0, go figure!)
*/
if releaseVersionScheme == "csvEpochAppend" {
re := regexp.MustCompile(`\.[[:digit:]]{10,}\.p`)
operatorConditionEpoch := re.FindString(operatorConditionName)
if operatorConditionEpoch == "" {
return openstackReleaseVersion
} else {
return openstackReleaseVersion + operatorConditionEpoch
}
}
return openstackReleaseVersion
}

// GetOpenStackReleaseVersion - returns the OpenStack release version
func GetOpenStackReleaseVersion(envVars []string) string {

return getOpenStackReleaseVersion(
util.GetEnvVar("OPENSTACK_RELEASE_VERSION", ""),
// can be set to csvEpochAppend
util.GetEnvVar("OPENSTACK_RELEASE_VERSION_SCHEME", ""),
// NOTE: dprince this is essentially the CSV version. OLM sets this to provide
// a way for the controller-manager to know the operator condition name
// we do it this way to *avoid requiring the CSV structs in this operator*
util.GetEnvVar("OPERATOR_CONDITION_NAME", ""),
)

}
4 changes: 2 additions & 2 deletions apis/core/v1beta1/openstackversion_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package v1beta1

import (
"context"
"os"

apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/validation/field"

"github.com/openstack-k8s-operators/lib-common/modules/common/util"
"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -173,7 +173,7 @@ func (r *OpenStackVersion) ValidateDelete() (admission.Warnings, error) {
// SetupVersionDefaults -
func SetupVersionDefaults() {
openstackVersionDefaults := OpenStackVersionDefaults{
AvailableVersion: util.GetEnvVar("OPENSTACK_RELEASE_VERSION", ""),
AvailableVersion: GetOpenStackReleaseVersion(os.Environ()),
}

SetupOpenStackVersionDefaults(openstackVersionDefaults)
Expand Down
1 change: 1 addition & 0 deletions controllers/core/openstackversion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func SetupVersionDefaults() {
localVars[envArr[0]] = &envArr[1]
}
}
envAvailableVersion = corev1beta1.GetOpenStackReleaseVersion(os.Environ())
envContainerImages = localVars
}

Expand Down

0 comments on commit 5656b32

Please sign in to comment.