Skip to content

Commit 2cc7a1e

Browse files
committed
fix: allow precompiled doca tag in webhook
For example: doca3.1-25.07-0.9.7.0-0-5.14.0-427.87.1.el9_4.x86_64-rhcos4.18-amd64 doca3.1.0-25.07-0.9.7.0-0-5.15.0-151-generic-ubuntu22.04-amd64 25.01-0.6.0.0-0-6.8.0-1019-oracle-ubuntu22.04-arm64 Signed-off-by: Fred Rolland <[email protected]>
1 parent 1001834 commit 2cc7a1e

File tree

2 files changed

+60
-4
lines changed

2 files changed

+60
-4
lines changed

api/v1alpha1/validator/nicclusterpolicy_webhook.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ func (ofedSpec *ofedDriverSpecWrapper) validateVersion(fldPath *field.Path) fiel
468468
// Perform version validation logic here
469469
if !isValidOFEDVersion(ofedSpec.Version) {
470470
allErrs = append(allErrs, field.Invalid(fldPath.Child("version"), ofedSpec.Version,
471-
`invalid OFED version, supported formats: "23.10-0.2.2.0", "24.01-0.3.3.1-0", "doca3.1-24.01-0.3.3.1-0", "sha256:9a831bfdf85f313b1f5749b7c9b2673bb8fff18b4ff768c9242dabaa4468e449"`))
471+
`invalid OFED version, supported formats: "23.10-0.2.2.0", "24.01-0.3.3.1-0", "25.01-0.6.0.0-0-6.8.0-1019-oracle-ubuntu22.04-arm64", "doca3.1-24.01-0.3.3.1-0", "doca3.1-25.07-0.9.7.0-0-5.14.0-427.87.1.el9_4.x86_64-rhcos4.18-amd64", "sha256:9a831bfdf85f313b1f5749b7c9b2673bb8fff18b4ff768c9242dabaa4468e449"`))
472472
}
473473
return allErrs
474474
}
@@ -711,9 +711,11 @@ func isValidOFEDVersion(version string) bool {
711711
// Support multiple OFED version formats:
712712
// 1. Old scheme: "23.10-0.2.2.0" or "23.10-0.2.2.0.1"
713713
// 2. New scheme: "24.01-0.3.3.1-0"
714-
// 3. DOCA prefix: "doca3.1.0-25.07-0.6.6.0-0"
715-
// 4. SHA256 format: "sha256:9a831bfdf85f313b1f5749b7c9b2673bb8fff18b4ff768c9242dabaa4468e449"
716-
versionPattern := `^(sha256:[a-fA-F0-9]{64}|doca\d+\.\d+\.\d+-\d+\.\d+-\d+\.\d+\.\d+\.\d+-\d+|\d+\.\d+-\d+(\.\d+)*(-\d+)?)$`
714+
// 3. New scheme with kernel-specific suffix: "25.01-0.6.0.0-0-6.8.0-1019-oracle-ubuntu22.04-arm64"
715+
// 4. DOCA prefix: "doca3.1.0-25.07-0.6.6.0-0"
716+
// 5. DOCA prefix with kernel-specific suffix: "doca3.1-25.07-0.9.7.0-0-5.14.0-427.87.1.el9_4.x86_64-rhcos4.18-amd64"
717+
// 6. SHA256 format: "sha256:9a831bfdf85f313b1f5749b7c9b2673bb8fff18b4ff768c9242dabaa4468e449"
718+
versionPattern := `^(sha256:[a-fA-F0-9]{64}|doca\d+\.\d+(\.\d+)?-\d+\.\d+-\d+\.\d+\.\d+\.\d+-\d+(-[\w\.\-]+)*|\d+\.\d+-\d+(\.\d+)*(-\d+)?(-[\w\.\-]+)*)$`
717719
versionRegex := regexp.MustCompile(versionPattern)
718720
return versionRegex.MatchString(version)
719721
}

api/v1alpha1/validator/nicclusterpolicy_webhook_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,42 @@ var _ = Describe("Validate", func() {
154154
_, err := validator.ValidateCreate(context.TODO(), nicClusterPolicy)
155155
Expect(err).NotTo(HaveOccurred())
156156
})
157+
It("Valid MOFED version (with doca prefix and kernel-specific suffix)", func() {
158+
validator := nicClusterPolicyValidator{}
159+
nicClusterPolicy := &v1alpha1.NicClusterPolicy{
160+
ObjectMeta: metav1.ObjectMeta{Name: "test"},
161+
Spec: v1alpha1.NicClusterPolicySpec{
162+
OFEDDriver: &v1alpha1.OFEDDriverSpec{
163+
ImageSpec: v1alpha1.ImageSpec{
164+
Image: "mofed",
165+
Repository: "ghcr.io/mellanox",
166+
Version: "doca3.1-25.07-0.9.7.0-0-5.14.0-427.87.1.el9_4.x86_64-rhcos4.18-amd64",
167+
ImagePullSecrets: []string{},
168+
},
169+
},
170+
},
171+
}
172+
_, err := validator.ValidateCreate(context.TODO(), nicClusterPolicy)
173+
Expect(err).NotTo(HaveOccurred())
174+
})
175+
It("Valid MOFED version (with doca prefix and kernel-specific suffix for Ubuntu)", func() {
176+
validator := nicClusterPolicyValidator{}
177+
nicClusterPolicy := &v1alpha1.NicClusterPolicy{
178+
ObjectMeta: metav1.ObjectMeta{Name: "test"},
179+
Spec: v1alpha1.NicClusterPolicySpec{
180+
OFEDDriver: &v1alpha1.OFEDDriverSpec{
181+
ImageSpec: v1alpha1.ImageSpec{
182+
Image: "mofed",
183+
Repository: "ghcr.io/mellanox",
184+
Version: "doca3.1.0-25.07-0.9.7.0-0-5.15.0-151-generic-ubuntu22.04-amd64",
185+
ImagePullSecrets: []string{},
186+
},
187+
},
188+
},
189+
}
190+
_, err := validator.ValidateCreate(context.TODO(), nicClusterPolicy)
191+
Expect(err).NotTo(HaveOccurred())
192+
})
157193
It("Valid MOFED version", func() {
158194
validator := nicClusterPolicyValidator{}
159195
nicClusterPolicy := &v1alpha1.NicClusterPolicy{
@@ -172,6 +208,24 @@ var _ = Describe("Validate", func() {
172208
_, err := validator.ValidateCreate(context.TODO(), nicClusterPolicy)
173209
Expect(err).NotTo(HaveOccurred())
174210
})
211+
It("Valid MOFED version (with kernel-specific suffix for ARM64)", func() {
212+
validator := nicClusterPolicyValidator{}
213+
nicClusterPolicy := &v1alpha1.NicClusterPolicy{
214+
ObjectMeta: metav1.ObjectMeta{Name: "test"},
215+
Spec: v1alpha1.NicClusterPolicySpec{
216+
OFEDDriver: &v1alpha1.OFEDDriverSpec{
217+
ImageSpec: v1alpha1.ImageSpec{
218+
Image: "mofed",
219+
Repository: "ghcr.io/mellanox",
220+
Version: "25.01-0.6.0.0-0-6.8.0-1019-oracle-ubuntu22.04-arm64",
221+
ImagePullSecrets: []string{},
222+
},
223+
},
224+
},
225+
}
226+
_, err := validator.ValidateCreate(context.TODO(), nicClusterPolicy)
227+
Expect(err).NotTo(HaveOccurred())
228+
})
175229
It("InValid MOFED version", func() {
176230
validator := nicClusterPolicyValidator{}
177231
nicClusterPolicy := &v1alpha1.NicClusterPolicy{

0 commit comments

Comments
 (0)