Skip to content

Commit f08a985

Browse files
mgoerenskomish
authored andcommitted
Use external library to get the OCP versions range
The translation of range of Kubernetes version to range of OCP versions was previsouly inconsistent accross chart-verifier and the certification pipeline. The code that performs this translation has now been externalized to the github.com/opdev/get-ocp-range repository. See openshift-helm-charts/charts#1032
1 parent e7ed9c6 commit f08a985

File tree

4 files changed

+24
-104
lines changed

4 files changed

+24
-104
lines changed

go.mod

+7-6
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ go 1.20
44

55
require (
66
github.com/Masterminds/semver v1.5.0
7-
github.com/Masterminds/sprig/v3 v3.2.3
87
github.com/google/go-cmp v0.5.9
98
github.com/google/uuid v1.3.1
109
github.com/helm/chart-testing/v3 v3.9.0
1110
github.com/imdario/mergo v0.3.13
1211
github.com/mitchellh/go-homedir v1.1.0
1312
github.com/mitchellh/hashstructure/v2 v2.0.2
13+
github.com/opdev/getocprange v0.0.0-20230929103806-05c46c06dbbe
1414
github.com/spf13/cobra v1.7.0
1515
github.com/spf13/viper v1.16.0
1616
github.com/stretchr/testify v1.8.4
@@ -31,6 +31,7 @@ require (
3131
github.com/MakeNowJust/heredoc v1.0.0 // indirect
3232
github.com/Masterminds/goutils v1.1.1 // indirect
3333
github.com/Masterminds/semver/v3 v3.2.1 // indirect
34+
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
3435
github.com/Masterminds/squirrel v1.5.4 // indirect
3536
github.com/asaskevich/govalidator v0.0.0-20200428143746-21a406dcc535 // indirect
3637
github.com/beorn7/perks v1.0.1 // indirect
@@ -129,13 +130,13 @@ require (
129130
go.opentelemetry.io/otel v1.14.0 // indirect
130131
go.opentelemetry.io/otel/trace v1.14.0 // indirect
131132
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
132-
golang.org/x/crypto v0.11.0 // indirect
133-
golang.org/x/net v0.13.0 // indirect
133+
golang.org/x/crypto v0.12.0 // indirect
134+
golang.org/x/net v0.14.0 // indirect
134135
golang.org/x/oauth2 v0.8.0 // indirect
135136
golang.org/x/sync v0.2.0 // indirect
136-
golang.org/x/sys v0.10.0 // indirect
137-
golang.org/x/term v0.10.0 // indirect
138-
golang.org/x/text v0.11.0 // indirect
137+
golang.org/x/sys v0.12.0 // indirect
138+
golang.org/x/term v0.11.0 // indirect
139+
golang.org/x/text v0.12.0 // indirect
139140
golang.org/x/time v0.3.0 // indirect
140141
google.golang.org/appengine v1.6.7 // indirect
141142
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect

go.sum

+15-13
Original file line numberDiff line numberDiff line change
@@ -487,8 +487,10 @@ github.com/nelsam/hel/v2 v2.3.2/go.mod h1:1ZTGfU2PFTOd5mx22i5O0Lc2GY933lQ2wb/ggy
487487
github.com/nelsam/hel/v2 v2.3.3/go.mod h1:1ZTGfU2PFTOd5mx22i5O0Lc2GY933lQ2wb/ggy+rL3w=
488488
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
489489
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
490-
github.com/onsi/ginkgo/v2 v2.9.4 h1:xR7vG4IXt5RWx6FfIjyAtsoMAtnc3C/rFXBBd2AjZwE=
491-
github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE=
490+
github.com/onsi/ginkgo/v2 v2.12.1 h1:uHNEO1RP2SpuZApSkel9nEh1/Mu+hmQe7Q+Pepg5OYA=
491+
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
492+
github.com/opdev/getocprange v0.0.0-20230929103806-05c46c06dbbe h1:k1yKfYLgvB7XNtQdtdQRfAiIQE2aLgr8SVo2IwGfmFs=
493+
github.com/opdev/getocprange v0.0.0-20230929103806-05c46c06dbbe/go.mod h1:QJPhmPUW0fNoGwfZkxX3tf+yuDOYu4dwxZ6o7rtCAGc=
492494
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
493495
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
494496
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b h1:YWuSjZCQAPM8UUBLkYUk1e+rZcvWHJmFb6i6rM44Xs8=
@@ -672,8 +674,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
672674
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
673675
golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4=
674676
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
675-
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
676-
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
677+
golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk=
678+
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=
677679
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
678680
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
679681
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
@@ -758,8 +760,8 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx
758760
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
759761
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
760762
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
761-
golang.org/x/net v0.13.0 h1:Nvo8UFsZ8X3BhAC9699Z1j7XQ3rsZnUUm7jfBEk1ueY=
762-
golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
763+
golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14=
764+
golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI=
763765
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
764766
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
765767
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -851,15 +853,15 @@ golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBc
851853
golang.org/x/sys v0.0.0-20221013171732-95e765b1cc43/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
852854
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
853855
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
854-
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
855-
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
856+
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
857+
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
856858
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
857859
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
858860
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
859861
golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc=
860862
golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ=
861-
golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c=
862-
golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o=
863+
golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0=
864+
golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU=
863865
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
864866
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
865867
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -871,8 +873,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
871873
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
872874
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
873875
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
874-
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
875-
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
876+
golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc=
877+
golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
876878
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
877879
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
878880
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
@@ -934,7 +936,7 @@ golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
934936
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
935937
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
936938
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
937-
golang.org/x/tools v0.8.0 h1:vSDcovVPld282ceKgDimkRSC8kpaH1dgyc9UMzlt84Y=
939+
golang.org/x/tools v0.12.0 h1:YW6HUoUmYBpwSgyaGaZq1fHjrBjX1rlpZ54T6mu2kss=
938940
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
939941
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
940942
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

internal/chartverifier/checks/checks.go

+2-40
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ import (
2626
"path"
2727
"strings"
2828

29-
"github.com/Masterminds/sprig/v3"
30-
"golang.org/x/mod/semver"
29+
"github.com/opdev/getocprange"
3130
"helm.sh/helm/v3/pkg/action"
3231
"helm.sh/helm/v3/pkg/lint"
3332
"helm.sh/helm/v3/pkg/lint/support"
@@ -196,7 +195,7 @@ func HasKubeVersion_V1_1(opts *CheckOptions) (Result, error) {
196195
r := NewResult(false, KuberVersionNotSpecified)
197196

198197
if c.Metadata.KubeVersion != "" {
199-
OCPRange, err := getOCPRange(c.Metadata.KubeVersion)
198+
OCPRange, err := getocprange.GetOCPRange(c.Metadata.KubeVersion)
200199
if err != nil {
201200
r = NewResult(false, err.Error())
202201
} else {
@@ -431,43 +430,6 @@ func parseImageReference(image string) pyxis.ImageReference {
431430
return imageRef
432431
}
433432

434-
func getOCPRange(kubeVersionRange string) (string, error) {
435-
semverCompare := sprig.GenericFuncMap()["semverCompare"].(func(string, string) (bool, error))
436-
minOCPVersion := ""
437-
maxOCPVersion := ""
438-
for kubeVersion, OCPVersion := range tool.GetKubeOpenShiftVersionMap() {
439-
match, err := semverCompare(kubeVersionRange, kubeVersion)
440-
if err != nil {
441-
return "", fmt.Errorf("%s : %s", KuberVersionProcessingError, err)
442-
}
443-
if match {
444-
testOCPVersion := fmt.Sprintf("v%s", OCPVersion)
445-
if minOCPVersion == "" || semver.Compare(testOCPVersion, fmt.Sprintf("v%s", minOCPVersion)) < 0 {
446-
minOCPVersion = OCPVersion
447-
}
448-
if maxOCPVersion == "" || semver.Compare(testOCPVersion, fmt.Sprintf("v%s", maxOCPVersion)) > 0 {
449-
maxOCPVersion = OCPVersion
450-
}
451-
}
452-
}
453-
// Check if min ocp range is open ended, for example 1.* or >-=1.20
454-
// To do this see if 1.999 is valid for the min OCP version range, not perfect but works until kubernetes hits 2.0.
455-
if minOCPVersion != "" {
456-
match, _ := semverCompare(kubeVersionRange, "1.999")
457-
if match {
458-
return fmt.Sprintf(">=%s", minOCPVersion), nil
459-
} else {
460-
if minOCPVersion == maxOCPVersion {
461-
return minOCPVersion, nil
462-
} else {
463-
return fmt.Sprintf("%s - %s", minOCPVersion, maxOCPVersion), nil
464-
}
465-
}
466-
}
467-
468-
return "", fmt.Errorf("%s : Failed to determine a minimum OCP version", KuberVersionProcessingError)
469-
}
470-
471433
func downloadFile(fileURL *url.URL, directory string) (string, error) {
472434
// Create blank file
473435
filePath := path.Join(directory, path.Base(fileURL.Path))

internal/chartverifier/checks/checks_test.go

-45
Original file line numberDiff line numberDiff line change
@@ -549,51 +549,6 @@ func TestRequiredAnnotationsPresent(t *testing.T) {
549549
}
550550
}
551551

552-
func TestSemVers(t *testing.T) {
553-
// Vault: kubeVersion: '>= 1.14.0-0'
554-
// IBM: kubeversion: '>=1.10.1-0'
555-
// Fortanix : kubeversion: '>= 1.16.0 < 1.22.0'
556-
// Wildfly: kubeversion: ""
557-
// Infispan: kubeversion: ""
558-
559-
type testCase struct {
560-
kubeVersion string
561-
OCPRange string
562-
}
563-
564-
// nolint:unused // TODO(komish): Identify historical purpose of this type
565-
// before considering for removal.
566-
type TestError struct {
567-
expectedOCPRange string
568-
gotOCORange string
569-
}
570-
571-
testCases := []testCase{
572-
{kubeVersion: "~1.22-0", OCPRange: "4.9"},
573-
{kubeVersion: "1.22.*", OCPRange: "4.9"},
574-
{kubeVersion: "^1.22", OCPRange: ">=4.9"},
575-
{kubeVersion: ">=1.20-0", OCPRange: ">=4.7"},
576-
{kubeVersion: "1.21 - 1.22", OCPRange: "4.8 - 4.9"},
577-
{kubeVersion: ">1.20", OCPRange: ">=4.8"},
578-
{kubeVersion: "~1.21", OCPRange: "4.8"},
579-
{kubeVersion: ">= 1.14.0-0", OCPRange: ">=4.2"},
580-
{kubeVersion: "1.16 - 1.21", OCPRange: "4.3 - 4.8"},
581-
{kubeVersion: "*", OCPRange: ">=4.1"},
582-
{kubeVersion: ">= 1.23.0 < 1.26.3", OCPRange: "4.10 - 4.13"},
583-
}
584-
585-
for _, test := range testCases {
586-
t.Run(fmt.Sprintf("Check kube version %s", test.kubeVersion), func(t *testing.T) {
587-
OCPRange, err := getOCPRange(test.kubeVersion)
588-
if err != nil {
589-
require.Equal(t, test.OCPRange, fmt.Sprintf("%v", err))
590-
} else {
591-
require.Equal(t, test.OCPRange, OCPRange)
592-
}
593-
})
594-
}
595-
}
596-
597552
func TestSignatureIsValid(t *testing.T) {
598553
type testCase struct {
599554
description string

0 commit comments

Comments
 (0)