Skip to content

Commit

Permalink
Merge pull request #1062 from dprince/csvEpochVersion
Browse files Browse the repository at this point in the history
OpenStackVersion: Add releaseVersionScheme and csvVersionAppend support
  • Loading branch information
openshift-merge-bot[bot] authored Sep 18, 2024
2 parents 19b20d7 + 7e218cb commit 27e5020
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
CRD_MARKDOWN ?= $(LOCALBIN)/crd-to-markdown
GINKGO ?= $(LOCALBIN)/ginkgo
GINKGO_TESTS ?= ./tests/... ./apis/client/...
GINKGO_TESTS ?= ./tests/... ./apis/client/... ./apis/core/... ./apis/dataplane/...

KUTTL ?= $(LOCALBIN)/kubectl-kuttl

Expand Down
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
40 changes: 40 additions & 0 deletions apis/core/v1beta1/version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package v1beta1

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("OpenStackReleaseVersion", func() {

Context("test interal getOpenStackReleaseVersion", func() {

// NOTE: this is the default behavior where OPENSTACK_RELEASE_VERSION is just an environment variable
// and enables the clearest understanding of the version number with regards to testing upgrades
It("Generates a default version based on the OPENSTACK_RELEASE_VERSION when no mode is set", func() {
Expect(
getOpenStackReleaseVersion("1.2.3", "", "openstack-operator.v1.0.0-0.1724144685.p"),
).To(Equal("1.2.3"))

})

It("Generates a default version based on the OPENSTACK_RELEASE_VERSION when invalid mode is set", func() {
Expect(
getOpenStackReleaseVersion("1.2.3", "asdf", "openstack-operator.v1.0.0-0.1724144685.p"),
).To(Equal("1.2.3"))

})

// NOTE: this is what some downstream projects use for custom release automation
// Will envolve extra understanding of the version number when testing upgrades with regards to how the
// epoch gets appended
It("Generates a version which appends the epoch when csvEpochAppend is enabled", func() {
Expect(
getOpenStackReleaseVersion("1.2.3", "csvEpochAppend", "openstack-operator.v1.0.0-0.1234567890.p"),
).To(Equal("1.2.3.1234567890.p"))

})

})

})
7 changes: 4 additions & 3 deletions apis/core/v1beta1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ package v1beta1

import (
"testing"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

// These tests use Ginkgo (BDD-style Go testing framework). Refer to
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
// Implement later
func TestAPIs(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Controller v1beta1 Suite")
}
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 27e5020

Please sign in to comment.