From e5b70e8462de2fe1a7e8ec9a24a554da101a7c9e Mon Sep 17 00:00:00 2001 From: Swati Sehgal Date: Thu, 14 Jul 2022 10:26:29 +0100 Subject: [PATCH] selinuxpolicy: Obtain the version from the top level CommonOption 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 --- pkg/commands/render.go | 1 + pkg/deployer/updaters/objects.go | 7 ++- pkg/deployer/updaters/updaters.go | 1 + pkg/manifests/rte/rte.go | 8 +-- pkg/manifests/rte/rte_test.go | 99 +++++++++++++++++++++++-------- 5 files changed, 80 insertions(+), 36 deletions(-) diff --git a/pkg/commands/render.go b/pkg/commands/render.go index 4e62dbe4..d0d8d29d 100644 --- a/pkg/commands/render.go +++ b/pkg/commands/render.go @@ -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, diff --git a/pkg/deployer/updaters/objects.go b/pkg/deployer/updaters/objects.go index 0d981d6b..14caff17 100644 --- a/pkg/deployer/updaters/objects.go +++ b/pkg/deployer/updaters/objects.go @@ -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 } @@ -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 } @@ -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 } diff --git a/pkg/deployer/updaters/updaters.go b/pkg/deployer/updaters/updaters.go index 845ef356..81937d40 100644 --- a/pkg/deployer/updaters/updaters.go +++ b/pkg/deployer/updaters/updaters.go @@ -35,6 +35,7 @@ const ( type Options struct { Platform platform.Platform + PlatformVersion platform.Version WaitCompletion bool PullIfNotPresent bool RTEConfigData string diff --git a/pkg/manifests/rte/rte.go b/pkg/manifests/rte/rte.go index 7e6d6dab..61102450 100644 --- a/pkg/manifests/rte/rte.go +++ b/pkg/manifests/rte/rte.go @@ -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" @@ -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 { diff --git a/pkg/manifests/rte/rte_test.go b/pkg/manifests/rte/rte_test.go index 5ddb9afd..2ce91e61 100644 --- a/pkg/manifests/rte/rte_test.go +++ b/pkg/manifests/rte/rte_test.go @@ -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 { @@ -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{}) @@ -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") + } } }