Skip to content

Commit

Permalink
selinuxpolicy: Obtain the version from the top level CommonOption
Browse files Browse the repository at this point in the history
Rather than calling detect.Version in the manifest package, we obtain
the version from the top level CommonOptions and pass it all the way
to the manifest package where the platform version is taken into
consideration when loading the selinux policy.

Signed-off-by: Swati Sehgal <[email protected]>
  • Loading branch information
swatisehgal committed Jul 14, 2022
1 parent 332e9bb commit e5b70e8
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 36 deletions.
1 change: 1 addition & 0 deletions pkg/commands/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ func makeUpdaterObjects(commonOpts *CommonOptions) ([]client.Object, string, err
}

opts := updaters.Options{
PlatformVersion: commonOpts.UserPlatformVersion,
Platform: commonOpts.UserPlatform,
PullIfNotPresent: commonOpts.PullIfNotPresent,
RTEConfigData: commonOpts.RTEConfigData,
Expand Down
7 changes: 4 additions & 3 deletions pkg/deployer/updaters/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ import (
)

func GetObjects(opts Options, updaterType, namespace string) ([]client.Object, error) {

if updaterType == RTE {
mf, err := rtemanifests.GetManifests(opts.Platform, namespace)
mf, err := rtemanifests.GetManifests(opts.Platform, opts.PlatformVersion, namespace)
if err != nil {
return nil, err
}
Expand All @@ -47,7 +48,7 @@ func GetObjects(opts Options, updaterType, namespace string) ([]client.Object, e

func getCreatableObjects(opts Options, hp *deployer.Helper, log tlog.Logger, updaterType, namespace string) ([]deployer.WaitableObject, error) {
if updaterType == RTE {
mf, err := rtemanifests.GetManifests(opts.Platform, namespace)
mf, err := rtemanifests.GetManifests(opts.Platform, opts.PlatformVersion, namespace)
if err != nil {
return nil, err
}
Expand All @@ -65,7 +66,7 @@ func getCreatableObjects(opts Options, hp *deployer.Helper, log tlog.Logger, upd

func getDeletableObjects(opts Options, hp *deployer.Helper, log tlog.Logger, updaterType, namespace string) ([]deployer.WaitableObject, error) {
if updaterType == RTE {
mf, err := rtemanifests.GetManifests(opts.Platform, namespace)
mf, err := rtemanifests.GetManifests(opts.Platform, opts.PlatformVersion, namespace)
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/deployer/updaters/updaters.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (

type Options struct {
Platform platform.Platform
PlatformVersion platform.Version
WaitCompletion bool
PullIfNotPresent bool
RTEConfigData string
Expand Down
8 changes: 1 addition & 7 deletions pkg/manifests/rte/rte.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

"github.com/k8stopologyawareschedwg/deployer/pkg/deployer"
"github.com/k8stopologyawareschedwg/deployer/pkg/deployer/platform"
"github.com/k8stopologyawareschedwg/deployer/pkg/deployer/platform/detect"
"github.com/k8stopologyawareschedwg/deployer/pkg/deployer/wait"
"github.com/k8stopologyawareschedwg/deployer/pkg/manifests"
"github.com/k8stopologyawareschedwg/deployer/pkg/tlog"
Expand Down Expand Up @@ -246,15 +245,10 @@ func New(plat platform.Platform) Manifests {
return mf
}

func GetManifests(plat platform.Platform, namespace string) (Manifests, error) {
func GetManifests(plat platform.Platform, version platform.Version, namespace string) (Manifests, error) {
var err error
mf := New(plat)

version, err := detect.Version(plat)
if err != nil {
return mf, err
}

if plat == platform.OpenShift {
mf.MachineConfig, err = manifests.MachineConfig(manifests.ComponentResourceTopologyExporter, version)
if err != nil {
Expand Down
99 changes: 73 additions & 26 deletions pkg/manifests/rte/rte_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,37 @@ import (

func TestClone(t *testing.T) {
type testCase struct {
name string
mf Manifests
plat platform.Platform
name string
mf Manifests
plat platform.Platform
platVersion platform.Version
}

testCases := []testCase{
{
name: "kubernetes manifests",
plat: platform.Kubernetes,
name: "kubernetes manifests",
plat: platform.Kubernetes,
platVersion: platform.Version("1.23"),
},
{
name: "kubernetes manifests",
plat: platform.Kubernetes,
platVersion: platform.Version("1.24"),
},
{
name: "openshift manifests",
plat: platform.OpenShift,
name: "openshift manifests",
plat: platform.OpenShift,
platVersion: platform.Version("4.10"),
},
{
name: "openshift manifests",
plat: platform.OpenShift,
platVersion: platform.Version("4.11"),
},
}

for _, tc := range testCases {
tc.mf, _ = GetManifests(tc.plat, "")
tc.mf, _ = GetManifests(tc.plat, tc.platVersion, "")
cMf := tc.mf.Clone()

if &cMf == &tc.mf {
Expand All @@ -53,24 +66,37 @@ func TestClone(t *testing.T) {

func TestRender(t *testing.T) {
type testCase struct {
name string
mf Manifests
plat platform.Platform
name string
mf Manifests
plat platform.Platform
platVersion platform.Version
}

testCases := []testCase{
{
name: "kubernetes manifests",
plat: platform.Kubernetes,
name: "kubernetes manifests 1.23",
plat: platform.Kubernetes,
platVersion: platform.Version("1.23"),
},
{
name: "openshift manifests",
plat: platform.OpenShift,
name: "kubernetes manifests 1.24",
plat: platform.Kubernetes,
platVersion: platform.Version("1.24"),
},
{
name: "openshift manifests 4.10",
plat: platform.OpenShift,
platVersion: platform.Version("4.10"),
},
{
name: "openshift manifests 4.11",
plat: platform.OpenShift,
platVersion: platform.Version("4.11"),
},
}

for _, tc := range testCases {
tc.mf, _ = GetManifests(tc.plat, "")
tc.mf, _ = GetManifests(tc.plat, tc.platVersion, "")
mfBeforeRender := tc.mf.Clone()
uMf := tc.mf.Render(RenderOptions{})

Expand All @@ -84,20 +110,41 @@ func TestRender(t *testing.T) {
}

func TestGetManifestsOpenShift(t *testing.T) {
mf, err := GetManifests(platform.OpenShift, "test")
if err != nil {
t.Fatalf("unexpected error: %v", err)
type testCase struct {
name string
// mf Manifests
plat platform.Platform
platVersion platform.Version
}

if mf.SecurityContextConstraint == nil {
t.Fatalf("no security context constraint is generated for the OpenShift platform")
testCases := []testCase{
{
name: "openshift manifests 4.10",
plat: platform.OpenShift,
platVersion: platform.Version("4.10"),
},
{
name: "openshift manifests 4.11",
plat: platform.OpenShift,
platVersion: platform.Version("4.11"),
},
}
for _, tc := range testCases {
mf, err := GetManifests(tc.plat, tc.platVersion, "test")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

if mf.MachineConfig == nil {
t.Fatalf("no machine config is generated for the OpenShift platform")
}
if mf.SecurityContextConstraint == nil {
t.Fatalf("no security context constraint is generated for the OpenShift platform")
}

if mf.DaemonSet == nil {
t.Fatalf("no daemon set is generated for the OpenShift platform")
if mf.MachineConfig == nil {
t.Fatalf("no machine config is generated for the OpenShift platform")
}

if mf.DaemonSet == nil {
t.Fatalf("no daemon set is generated for the OpenShift platform")
}
}
}

0 comments on commit e5b70e8

Please sign in to comment.