-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically set
global.podSecurityStandards.enforced
to true
fo…
…r clusters >= 19.3.0. (#1659)
- Loading branch information
Showing
5 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package key | ||
|
||
import ( | ||
"github.com/blang/semver" | ||
"github.com/giantswarm/microerror" | ||
) | ||
|
||
func IsPSSRelease(getter LabelsGetter) (bool, error) { | ||
release := ReleaseVersion(getter) | ||
|
||
if release == "" { | ||
// Unable to get release from CR. | ||
return false, microerror.Maskf(unknownReleaseError, "cannot determine release version from CR") | ||
} | ||
|
||
releaseVersion, err := semver.ParseTolerant(release) | ||
if err != nil { | ||
return false, microerror.Mask(err) | ||
} | ||
|
||
return releaseVersion.Major >= 19 && releaseVersion.Minor >= 3, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package key | ||
|
||
import ( | ||
"testing" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"sigs.k8s.io/cluster-api/api/v1beta1" | ||
|
||
"github.com/giantswarm/cluster-operator/v5/pkg/label" | ||
) | ||
|
||
func TestIsPSSRelease(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
getter LabelsGetter | ||
want bool | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "= 19.3.0", | ||
getter: getClusterWithLabelVersion("19.3.0"), | ||
want: true, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "< 19.3.0", | ||
getter: getClusterWithLabelVersion("19.2.999999"), | ||
want: false, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "19.3.0 test version", | ||
getter: getClusterWithLabelVersion("19.3.0-blah"), | ||
want: true, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "> 19.3.0", | ||
getter: getClusterWithLabelVersion("19.3.1"), | ||
want: true, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := IsPSSRelease(tt.getter) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("IsPSSRelease() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if got != tt.want { | ||
t.Errorf("IsPSSRelease() got = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func getClusterWithLabelVersion(version string) *v1beta1.Cluster { | ||
return &v1beta1.Cluster{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Labels: map[string]string{ | ||
label.ReleaseVersion: version, | ||
}, | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters