Skip to content

Commit 27e5020

Browse files
Merge pull request #1062 from dprince/csvEpochVersion
OpenStackVersion: Add releaseVersionScheme and csvVersionAppend support
2 parents 19b20d7 + 7e218cb commit 27e5020

File tree

6 files changed

+90
-6
lines changed

6 files changed

+90
-6
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
260260
ENVTEST ?= $(LOCALBIN)/setup-envtest
261261
CRD_MARKDOWN ?= $(LOCALBIN)/crd-to-markdown
262262
GINKGO ?= $(LOCALBIN)/ginkgo
263-
GINKGO_TESTS ?= ./tests/... ./apis/client/...
263+
GINKGO_TESTS ?= ./tests/... ./apis/client/... ./apis/core/... ./apis/dataplane/...
264264

265265
KUTTL ?= $(LOCALBIN)/kubectl-kuttl
266266

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)

apis/core/v1beta1/version_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package v1beta1
2+
3+
import (
4+
. "github.com/onsi/ginkgo/v2"
5+
. "github.com/onsi/gomega"
6+
)
7+
8+
var _ = Describe("OpenStackReleaseVersion", func() {
9+
10+
Context("test interal getOpenStackReleaseVersion", func() {
11+
12+
// NOTE: this is the default behavior where OPENSTACK_RELEASE_VERSION is just an environment variable
13+
// and enables the clearest understanding of the version number with regards to testing upgrades
14+
It("Generates a default version based on the OPENSTACK_RELEASE_VERSION when no mode is set", func() {
15+
Expect(
16+
getOpenStackReleaseVersion("1.2.3", "", "openstack-operator.v1.0.0-0.1724144685.p"),
17+
).To(Equal("1.2.3"))
18+
19+
})
20+
21+
It("Generates a default version based on the OPENSTACK_RELEASE_VERSION when invalid mode is set", func() {
22+
Expect(
23+
getOpenStackReleaseVersion("1.2.3", "asdf", "openstack-operator.v1.0.0-0.1724144685.p"),
24+
).To(Equal("1.2.3"))
25+
26+
})
27+
28+
// NOTE: this is what some downstream projects use for custom release automation
29+
// Will envolve extra understanding of the version number when testing upgrades with regards to how the
30+
// epoch gets appended
31+
It("Generates a version which appends the epoch when csvEpochAppend is enabled", func() {
32+
Expect(
33+
getOpenStackReleaseVersion("1.2.3", "csvEpochAppend", "openstack-operator.v1.0.0-0.1234567890.p"),
34+
).To(Equal("1.2.3.1234567890.p"))
35+
36+
})
37+
38+
})
39+
40+
})

apis/core/v1beta1/webhook_suite_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ package v1beta1
1818

1919
import (
2020
"testing"
21+
. "github.com/onsi/ginkgo/v2"
22+
. "github.com/onsi/gomega"
2123
)
2224

23-
// These tests use Ginkgo (BDD-style Go testing framework). Refer to
24-
// http://onsi.github.io/ginkgo/ to learn more about Ginkgo.
25-
// Implement later
2625
func TestAPIs(t *testing.T) {
26+
RegisterFailHandler(Fail)
27+
RunSpecs(t, "Controller v1beta1 Suite")
2728
}

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)