diff --git a/pkg/commands/render.go b/pkg/commands/render.go index b17517c0..eb112d00 100644 --- a/pkg/commands/render.go +++ b/pkg/commands/render.go @@ -28,8 +28,8 @@ import ( "github.com/k8stopologyawareschedwg/deployer/pkg/deployer/platform" "github.com/k8stopologyawareschedwg/deployer/pkg/deployer/updaters" "github.com/k8stopologyawareschedwg/deployer/pkg/manifests" - "github.com/k8stopologyawareschedwg/deployer/pkg/manifests/api" - "github.com/k8stopologyawareschedwg/deployer/pkg/manifests/sched" + apimanifests "github.com/k8stopologyawareschedwg/deployer/pkg/manifests/api" + schedmanifests "github.com/k8stopologyawareschedwg/deployer/pkg/manifests/sched" "github.com/k8stopologyawareschedwg/deployer/pkg/options" ) @@ -61,7 +61,9 @@ func NewRenderAPICommand(env *deployer.Environment, commonOpts *options.Options, if commonOpts.UserPlatform == platform.Unknown { return fmt.Errorf("must explicitly select a cluster platform") } - apiManifests, err := api.GetManifests(commonOpts.UserPlatform) + apiManifests, err := apimanifests.NewWithOptions(options.Render{ + Platform: commonOpts.UserPlatform, + }) if err != nil { return err } @@ -90,7 +92,10 @@ func NewRenderSchedulerPluginCommand(env *deployer.Environment, commonOpts *opti return err } - schedManifests, err := sched.GetManifests(commonOpts.UserPlatform, namespace) + schedManifests, err := schedmanifests.NewWithOptions(options.Render{ + Platform: commonOpts.UserPlatform, + Namespace: namespace, + }) if err != nil { return err } @@ -159,7 +164,9 @@ func makeUpdaterObjects(commonOpts *options.Options) ([]client.Object, string, e func RenderManifests(env *deployer.Environment, commonOpts *options.Options) error { var objs []client.Object - apiManifests, err := api.GetManifests(commonOpts.UserPlatform) + apiManifests, err := apimanifests.NewWithOptions(options.Render{ + Platform: commonOpts.UserPlatform, + }) if err != nil { return err } @@ -175,7 +182,10 @@ func RenderManifests(env *deployer.Environment, commonOpts *options.Options) err } objs = append(objs, updaterObjs...) - schedManifests, err := sched.GetManifests(commonOpts.UserPlatform, updaterNs) + schedManifests, err := schedmanifests.NewWithOptions(options.Render{ + Platform: commonOpts.UserPlatform, + Namespace: updaterNs, + }) if err != nil { return err } diff --git a/pkg/deployer/api/api.go b/pkg/deployer/api/api.go index edd6f81c..b1148cf5 100644 --- a/pkg/deployer/api/api.go +++ b/pkg/deployer/api/api.go @@ -37,7 +37,9 @@ func Deploy(env *deployer.Environment, opts options.API) error { env = env.WithName("API") env.Log.Info("deploying topology-aware-scheduling API") - mf, err := apimanifests.GetManifests(opts.Platform) + mf, err := apimanifests.NewWithOptions(options.Render{ + Platform: opts.Platform, + }) if err != nil { return err } @@ -67,7 +69,9 @@ func Remove(env *deployer.Environment, opts options.API) error { env = env.WithName("API") env.Log.Info("removing topology-aware-scheduling API") - mf, err := apimanifests.GetManifests(opts.Platform) + mf, err := apimanifests.NewWithOptions(options.Render{ + Platform: opts.Platform, + }) if err != nil { return err } diff --git a/pkg/deployer/sched/sched.go b/pkg/deployer/sched/sched.go index ab7fa675..5987505f 100644 --- a/pkg/deployer/sched/sched.go +++ b/pkg/deployer/sched/sched.go @@ -37,7 +37,9 @@ func Deploy(env *deployer.Environment, opts options.Scheduler) error { env = env.WithName("SCD") env.Log.Info("deploying topology-aware-scheduling scheduler plugin") - mf, err := schedmanifests.GetManifests(opts.Platform, "") + mf, err := schedmanifests.NewWithOptions(options.Render{ + Platform: opts.Platform, + }) if err != nil { return err } @@ -72,7 +74,9 @@ func Remove(env *deployer.Environment, opts options.Scheduler) error { env = env.WithName("SCD") env.Log.Info("removing topology-aware-scheduling scheduler plugin") - mf, err := schedmanifests.GetManifests(opts.Platform, "") + mf, err := schedmanifests.NewWithOptions(options.Render{ + Platform: opts.Platform, + }) if err != nil { return err } diff --git a/pkg/deployer/updaters/objects.go b/pkg/deployer/updaters/objects.go index eda078db..65def0b5 100644 --- a/pkg/deployer/updaters/objects.go +++ b/pkg/deployer/updaters/objects.go @@ -32,7 +32,7 @@ import ( func GetObjects(opts options.Updater, updaterType, namespace string) ([]client.Object, error) { if updaterType == RTE { - mf, err := rtemanifests.GetManifests(opts.Platform, opts.PlatformVersion, namespace, opts.EnableCRIHooks, opts.CustomSELinuxPolicy) + mf, err := rtemanifests.NewWithOptions(renderOptionsFrom(opts, namespace)) if err != nil { return nil, err } @@ -43,7 +43,7 @@ func GetObjects(opts options.Updater, updaterType, namespace string) ([]client.O return ret.ToObjects(), nil } if updaterType == NFD { - mf, err := nfdmanifests.GetManifests(opts.Platform, namespace) + mf, err := nfdmanifests.NewWithOptions(renderOptionsFrom(opts, namespace)) if err != nil { return nil, err } @@ -58,7 +58,7 @@ func GetObjects(opts options.Updater, updaterType, namespace string) ([]client.O func getCreatableObjects(env *deployer.Environment, opts options.Updater, updaterType, namespace string) ([]objectwait.WaitableObject, error) { if updaterType == RTE { - mf, err := rtemanifests.GetManifests(opts.Platform, opts.PlatformVersion, namespace, opts.EnableCRIHooks, opts.CustomSELinuxPolicy) + mf, err := rtemanifests.NewWithOptions(renderOptionsFrom(opts, namespace)) if err != nil { return nil, err } @@ -69,7 +69,7 @@ func getCreatableObjects(env *deployer.Environment, opts options.Updater, update return rtewait.Creatable(ret, env.Cli, env.Log), nil } if updaterType == NFD { - mf, err := nfdmanifests.GetManifests(opts.Platform, namespace) + mf, err := nfdmanifests.NewWithOptions(renderOptionsFrom(opts, namespace)) if err != nil { return nil, err } @@ -84,7 +84,7 @@ func getCreatableObjects(env *deployer.Environment, opts options.Updater, update func getDeletableObjects(env *deployer.Environment, opts options.Updater, updaterType, namespace string) ([]objectwait.WaitableObject, error) { if updaterType == RTE { - mf, err := rtemanifests.GetManifests(opts.Platform, opts.PlatformVersion, namespace, opts.EnableCRIHooks, opts.CustomSELinuxPolicy) + mf, err := rtemanifests.NewWithOptions(renderOptionsFrom(opts, namespace)) if err != nil { return nil, err } @@ -95,7 +95,7 @@ func getDeletableObjects(env *deployer.Environment, opts options.Updater, update return rtewait.Deletable(ret, env.Cli, env.Log), nil } if updaterType == NFD { - mf, err := nfdmanifests.GetManifests(opts.Platform, namespace) + mf, err := nfdmanifests.NewWithOptions(renderOptionsFrom(opts, namespace)) if err != nil { return nil, err } @@ -115,3 +115,13 @@ func updaterDaemonOptionsFrom(opts options.Updater, namespace string) options.Up Namespace: namespace, } } + +func renderOptionsFrom(opts options.Updater, namespace string) options.Render { + return options.Render{ + Platform: opts.Platform, + PlatformVersion: opts.PlatformVersion, + Namespace: namespace, + EnableCRIHooks: opts.EnableCRIHooks, + CustomSELinuxPolicy: opts.CustomSELinuxPolicy, + } +} diff --git a/pkg/manifests/api/api.go b/pkg/manifests/api/api.go index 016fe3c3..8511ac6c 100644 --- a/pkg/manifests/api/api.go +++ b/pkg/manifests/api/api.go @@ -23,6 +23,7 @@ import ( "github.com/k8stopologyawareschedwg/deployer/pkg/deployer/platform" "github.com/k8stopologyawareschedwg/deployer/pkg/manifests" + "github.com/k8stopologyawareschedwg/deployer/pkg/options" ) type Manifests struct { @@ -57,9 +58,9 @@ func New(plat platform.Platform) Manifests { } } -func GetManifests(plat platform.Platform) (Manifests, error) { +func NewWithOptions(opts options.Render) (Manifests, error) { var err error - mf := New(plat) + mf := New(opts.Platform) mf.Crd, err = manifests.APICRD() if err != nil { @@ -68,3 +69,10 @@ func GetManifests(plat platform.Platform) (Manifests, error) { return mf, nil } + +// GetManifests is deprecated, use NewWithOptions in new code +func GetManifests(plat platform.Platform) (Manifests, error) { + return NewWithOptions(options.Render{ + Platform: plat, + }) +} diff --git a/pkg/manifests/api/api_test.go b/pkg/manifests/api/api_test.go index 5ed187e3..f8f9973a 100644 --- a/pkg/manifests/api/api_test.go +++ b/pkg/manifests/api/api_test.go @@ -21,6 +21,7 @@ import ( "testing" "github.com/k8stopologyawareschedwg/deployer/pkg/deployer/platform" + "github.com/k8stopologyawareschedwg/deployer/pkg/options" ) func TestClone(t *testing.T) { @@ -43,9 +44,11 @@ func TestClone(t *testing.T) { for _, tc := range testCases { var err error - tc.mf, err = GetManifests(tc.plat) + tc.mf, err = NewWithOptions(options.Render{ + Platform: tc.plat, + }) if err != nil { - t.Fatalf("GetManifests() failed: %v", err) + t.Fatalf("NewWithOptions() failed: %v", err) } cMf := tc.mf.Clone() @@ -75,9 +78,11 @@ func TestRender(t *testing.T) { for _, tc := range testCases { var err error - tc.mf, err = GetManifests(tc.plat) + tc.mf, err = NewWithOptions(options.Render{ + Platform: tc.plat, + }) if err != nil { - t.Fatalf("GetManifests() failed: %v", err) + t.Fatalf("NewWithOptions() failed: %v", err) } mfBeforeRender := tc.mf.Clone() uMf, err := tc.mf.Render() @@ -114,9 +119,11 @@ func TestToObjects(t *testing.T) { for _, tc := range testCases { var err error - tc.mf, err = GetManifests(tc.plat) + tc.mf, err = NewWithOptions(options.Render{ + Platform: tc.plat, + }) if err != nil { - t.Fatalf("GetManifests() failed: %v", err) + t.Fatalf("NewWithOptions() failed: %v", err) } objs := tc.mf.ToObjects() if len(objs) == 0 { diff --git a/pkg/manifests/nfd/nfd.go b/pkg/manifests/nfd/nfd.go index 4433524e..de49984e 100644 --- a/pkg/manifests/nfd/nfd.go +++ b/pkg/manifests/nfd/nfd.go @@ -87,16 +87,16 @@ func New(plat platform.Platform) Manifests { return mf } -func GetManifests(plat platform.Platform, namespace string) (Manifests, error) { +func NewWithOptions(opts options.Render) (Manifests, error) { var err error - mf := New(plat) + mf := New(opts.Platform) mf.Namespace, err = manifests.Namespace(manifests.ComponentNodeFeatureDiscovery) if err != nil { return mf, err } - mf.SATopologyUpdater, err = manifests.ServiceAccount(manifests.ComponentNodeFeatureDiscovery, manifests.SubComponentNodeFeatureDiscoveryTopologyUpdater, namespace) + mf.SATopologyUpdater, err = manifests.ServiceAccount(manifests.ComponentNodeFeatureDiscovery, manifests.SubComponentNodeFeatureDiscoveryTopologyUpdater, opts.Namespace) if err != nil { return mf, err } @@ -108,10 +108,18 @@ func GetManifests(plat platform.Platform, namespace string) (Manifests, error) { if err != nil { return mf, err } - mf.DSTopologyUpdater, err = manifests.DaemonSet(manifests.ComponentNodeFeatureDiscovery, manifests.SubComponentNodeFeatureDiscoveryTopologyUpdater, namespace) + mf.DSTopologyUpdater, err = manifests.DaemonSet(manifests.ComponentNodeFeatureDiscovery, manifests.SubComponentNodeFeatureDiscoveryTopologyUpdater, opts.Namespace) if err != nil { return mf, err } return mf, nil } + +// GetManifests is deprecated, use NewWithOptions in new code +func GetManifests(plat platform.Platform, namespace string) (Manifests, error) { + return NewWithOptions(options.Render{ + Platform: plat, + Namespace: namespace, + }) +} diff --git a/pkg/manifests/nfd/nfd_test.go b/pkg/manifests/nfd/nfd_test.go index 7ca7da16..261ba232 100644 --- a/pkg/manifests/nfd/nfd_test.go +++ b/pkg/manifests/nfd/nfd_test.go @@ -26,7 +26,7 @@ import ( const defaultNFDNamespace = "node-feature-discovery" -func TestGetManifests(t *testing.T) { +func TestNewWithOptions(t *testing.T) { type testCase struct { name string namespace string @@ -47,16 +47,19 @@ func TestGetManifests(t *testing.T) { } for _, tc := range testCases { - tc.mf, _ = GetManifests(tc.plat, tc.namespace) + tc.mf, _ = NewWithOptions(options.Render{ + Platform: tc.plat, + Namespace: tc.namespace, + }) for _, obj := range tc.mf.ToObjects() { if tc.namespace != "" { if obj.GetNamespace() != "" && obj.GetNamespace() != tc.namespace { - t.Errorf("testcase %q, GetManifests failed to create %q object named %q with correct namespace %q. got namespace %q instead ", + t.Errorf("testcase %q, NewWithOptions failed to create %q object named %q with correct namespace %q. got namespace %q instead ", tc.name, obj.GetObjectKind(), obj.GetName(), tc.namespace, obj.GetNamespace()) } } else { // no namespace provided we should have the default if obj.GetNamespace() != "" && obj.GetNamespace() != defaultNFDNamespace { - t.Errorf("testcase %q, GetManifests failed to create %q object named %q with default namespace %q. got namespace %q instead ", + t.Errorf("testcase %q, NewWithOptions failed to create %q object named %q with default namespace %q. got namespace %q instead ", tc.name, obj.GetObjectKind(), obj.GetName(), defaultNFDNamespace, obj.GetNamespace()) } } @@ -82,7 +85,9 @@ func TestClone(t *testing.T) { } for _, tc := range testCases { - tc.mf, _ = GetManifests(tc.plat, "") + tc.mf, _ = NewWithOptions(options.Render{ + Platform: tc.plat, + }) cMf := tc.mf.Clone() if &cMf == &tc.mf { @@ -110,7 +115,9 @@ func TestRender(t *testing.T) { } for _, tc := range testCases { - tc.mf, _ = GetManifests(tc.plat, "") + tc.mf, _ = NewWithOptions(options.Render{ + Platform: tc.plat, + }) mfBeforeUpdate := tc.mf.Clone() uMf, err := tc.mf.Render(options.UpdaterDaemon{}) if err != nil { diff --git a/pkg/manifests/rte/rte.go b/pkg/manifests/rte/rte.go index 6284e860..f9e8a989 100644 --- a/pkg/manifests/rte/rte.go +++ b/pkg/manifests/rte/rte.go @@ -181,32 +181,32 @@ func New(plat platform.Platform) Manifests { return mf } -func GetManifests(plat platform.Platform, version platform.Version, namespace string, withCRIHooks, withCustomSELinuxPolicy bool) (Manifests, error) { +func NewWithOptions(opts options.Render) (Manifests, error) { var err error - mf := New(plat) + mf := New(opts.Platform) - if plat == platform.OpenShift && withCustomSELinuxPolicy { - mf.MachineConfig, err = manifests.MachineConfig(manifests.ComponentResourceTopologyExporter, version, withCRIHooks) + if opts.Platform == platform.OpenShift && opts.CustomSELinuxPolicy { + mf.MachineConfig, err = manifests.MachineConfig(manifests.ComponentResourceTopologyExporter, opts.PlatformVersion, opts.EnableCRIHooks) if err != nil { return mf, err } } - if plat != platform.Kubernetes { - mf.SecurityContextConstraint, err = manifests.SecurityContextConstraint(manifests.ComponentResourceTopologyExporter, withCustomSELinuxPolicy) + if opts.Platform != platform.Kubernetes { + mf.SecurityContextConstraint, err = manifests.SecurityContextConstraint(manifests.ComponentResourceTopologyExporter, opts.CustomSELinuxPolicy) if err != nil { return mf, err } } - mf.ServiceAccount, err = manifests.ServiceAccount(manifests.ComponentResourceTopologyExporter, "", namespace) + mf.ServiceAccount, err = manifests.ServiceAccount(manifests.ComponentResourceTopologyExporter, "", opts.Namespace) if err != nil { return mf, err } - mf.Role, err = manifests.Role(manifests.ComponentResourceTopologyExporter, "", namespace) + mf.Role, err = manifests.Role(manifests.ComponentResourceTopologyExporter, "", opts.Namespace) if err != nil { return mf, err } - mf.RoleBinding, err = manifests.RoleBinding(manifests.ComponentResourceTopologyExporter, "", "", namespace) + mf.RoleBinding, err = manifests.RoleBinding(manifests.ComponentResourceTopologyExporter, "", "", opts.Namespace) if err != nil { return mf, err } @@ -218,9 +218,20 @@ func GetManifests(plat platform.Platform, version platform.Version, namespace st if err != nil { return mf, err } - mf.DaemonSet, err = manifests.DaemonSet(manifests.ComponentResourceTopologyExporter, "", namespace) + mf.DaemonSet, err = manifests.DaemonSet(manifests.ComponentResourceTopologyExporter, "", opts.Namespace) if err != nil { return mf, err } return mf, nil } + +// GetManifests is deprecated, use NewWithOptions in new code +func GetManifests(plat platform.Platform, version platform.Version, namespace string, withCRIHooks, withCustomSELinuxPolicy bool) (Manifests, error) { + return NewWithOptions(options.Render{ + Platform: plat, + PlatformVersion: version, + Namespace: namespace, + EnableCRIHooks: withCRIHooks, + CustomSELinuxPolicy: withCustomSELinuxPolicy, + }) +} diff --git a/pkg/manifests/rte/rte_test.go b/pkg/manifests/rte/rte_test.go index 70f24ec4..590d38d6 100644 --- a/pkg/manifests/rte/rte_test.go +++ b/pkg/manifests/rte/rte_test.go @@ -56,7 +56,12 @@ func TestClone(t *testing.T) { } for _, tc := range testCases { - tc.mf, _ = GetManifests(tc.plat, tc.platVersion, "", true, true) + tc.mf, _ = NewWithOptions(options.Render{ + Platform: tc.plat, + PlatformVersion: tc.platVersion, + EnableCRIHooks: true, + CustomSELinuxPolicy: true, + }) cMf := tc.mf.Clone() if &cMf == &tc.mf { @@ -97,7 +102,12 @@ func TestRender(t *testing.T) { } for _, tc := range testCases { - tc.mf, _ = GetManifests(tc.plat, tc.platVersion, "", true, true) + tc.mf, _ = NewWithOptions(options.Render{ + Platform: tc.plat, + PlatformVersion: tc.platVersion, + EnableCRIHooks: true, + CustomSELinuxPolicy: true, + }) mfBeforeRender := tc.mf.Clone() uMf, err := tc.mf.Render(options.UpdaterDaemon{}) if err != nil { @@ -113,7 +123,7 @@ func TestRender(t *testing.T) { } } -func TestGetManifestsOpenShift(t *testing.T) { +func TestNewWithOptionsOpenShift(t *testing.T) { type testCase struct { name string plat platform.Platform @@ -141,7 +151,13 @@ func TestGetManifestsOpenShift(t *testing.T) { }, } for _, tc := range testCases { - mf, err := GetManifests(tc.plat, tc.platVersion, "test", true, tc.withCustomSELinuxPolicy) + mf, err := NewWithOptions(options.Render{ + Platform: tc.plat, + PlatformVersion: tc.platVersion, + Namespace: "test", + EnableCRIHooks: true, + CustomSELinuxPolicy: tc.withCustomSELinuxPolicy, + }) if err != nil { t.Fatalf("unexpected error: %v", err) } diff --git a/pkg/manifests/sched/sched.go b/pkg/manifests/sched/sched.go index 3a595c23..18912188 100644 --- a/pkg/manifests/sched/sched.go +++ b/pkg/manifests/sched/sched.go @@ -193,9 +193,9 @@ func New(plat platform.Platform) Manifests { } } -func GetManifests(plat platform.Platform, namespace string) (Manifests, error) { +func NewWithOptions(opts options.Render) (Manifests, error) { var err error - mf := New(plat) + mf := New(opts.Platform) mf.Crd, err = manifests.SchedulerCRD() if err != nil { return mf, err @@ -209,7 +209,7 @@ func GetManifests(plat platform.Platform, namespace string) (Manifests, error) { if err != nil { return mf, err } - mf.SAScheduler, err = manifests.ServiceAccount(manifests.ComponentSchedulerPlugin, manifests.SubComponentSchedulerPluginScheduler, namespace) + mf.SAScheduler, err = manifests.ServiceAccount(manifests.ComponentSchedulerPlugin, manifests.SubComponentSchedulerPluginScheduler, opts.Namespace) if err != nil { return mf, err } @@ -221,24 +221,24 @@ func GetManifests(plat platform.Platform, namespace string) (Manifests, error) { if err != nil { return mf, err } - mf.RSchedulerElect, err = manifests.Role(manifests.ComponentSchedulerPlugin, manifests.SubComponentSchedulerPluginScheduler, namespace) + mf.RSchedulerElect, err = manifests.Role(manifests.ComponentSchedulerPlugin, manifests.SubComponentSchedulerPluginScheduler, opts.Namespace) if err != nil { return mf, err } - mf.RBSchedulerElect, err = manifests.RoleBinding(manifests.ComponentSchedulerPlugin, manifests.SubComponentSchedulerPluginScheduler, manifests.RoleNameLeaderElect, namespace) + mf.RBSchedulerElect, err = manifests.RoleBinding(manifests.ComponentSchedulerPlugin, manifests.SubComponentSchedulerPluginScheduler, manifests.RoleNameLeaderElect, opts.Namespace) if err != nil { return mf, err } - mf.RBSchedulerAuth, err = manifests.RoleBinding(manifests.ComponentSchedulerPlugin, manifests.SubComponentSchedulerPluginScheduler, manifests.RoleNameAuthReader, namespace) + mf.RBSchedulerAuth, err = manifests.RoleBinding(manifests.ComponentSchedulerPlugin, manifests.SubComponentSchedulerPluginScheduler, manifests.RoleNameAuthReader, opts.Namespace) if err != nil { return mf, err } - mf.DPScheduler, err = manifests.Deployment(manifests.ComponentSchedulerPlugin, manifests.SubComponentSchedulerPluginScheduler, "") + mf.DPScheduler, err = manifests.Deployment(manifests.ComponentSchedulerPlugin, manifests.SubComponentSchedulerPluginScheduler, opts.Namespace) if err != nil { return mf, err } - mf.SAController, err = manifests.ServiceAccount(manifests.ComponentSchedulerPlugin, manifests.SubComponentSchedulerPluginController, namespace) + mf.SAController, err = manifests.ServiceAccount(manifests.ComponentSchedulerPlugin, manifests.SubComponentSchedulerPluginController, opts.Namespace) if err != nil { return mf, err } @@ -250,7 +250,7 @@ func GetManifests(plat platform.Platform, namespace string) (Manifests, error) { if err != nil { return mf, err } - mf.RBController, err = manifests.RoleBinding(manifests.ComponentSchedulerPlugin, manifests.SubComponentSchedulerPluginController, "", namespace) + mf.RBController, err = manifests.RoleBinding(manifests.ComponentSchedulerPlugin, manifests.SubComponentSchedulerPluginController, "", opts.Namespace) if err != nil { return mf, err } @@ -262,6 +262,14 @@ func GetManifests(plat platform.Platform, namespace string) (Manifests, error) { return mf, nil } +// GetManifests is deprecated, use NewWithOptions in new code +func GetManifests(plat platform.Platform, namespace string) (Manifests, error) { + return NewWithOptions(options.Render{ + Platform: plat, + Namespace: namespace, + }) +} + func leaderElectionParamsFromOpts(opts options.Scheduler) (manifests.LeaderElectionParams, bool, error) { leap := manifests.LeaderElectionParams{} if !opts.LeaderElection { diff --git a/pkg/manifests/sched/sched_test.go b/pkg/manifests/sched/sched_test.go index b82b81c1..2b0a6309 100644 --- a/pkg/manifests/sched/sched_test.go +++ b/pkg/manifests/sched/sched_test.go @@ -46,7 +46,9 @@ func TestClone(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - mf, _ := GetManifests(tc.plat, "") + mf, _ := NewWithOptions(options.Render{ + Platform: tc.plat, + }) cMf := mf.Clone() if &cMf == &mf { @@ -75,9 +77,11 @@ func TestRender(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - mf, err := GetManifests(tc.plat, "") + mf, err := NewWithOptions(options.Render{ + Platform: tc.plat, + }) if err != nil { - t.Errorf("testcase %q, GetManifests(%s, \"\") failed: %v", tc.name, tc.plat, err) + t.Errorf("testcase %q, NewWithOptions(platform=%s) failed: %v", tc.name, tc.plat, err) } mfBeforeRender := mf.Clone() diff --git a/pkg/options/options.go b/pkg/options/options.go index e666e959..d5c77b87 100644 --- a/pkg/options/options.go +++ b/pkg/options/options.go @@ -98,6 +98,14 @@ type Updater struct { CustomSELinuxPolicy bool } +type Render struct { + Platform platform.Platform + PlatformVersion platform.Version + Namespace string + EnableCRIHooks bool + CustomSELinuxPolicy bool +} + func ForDaemonSet(commonOpts *Options) DaemonSet { return DaemonSet{ PullIfNotPresent: commonOpts.PullIfNotPresent, diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index 702c7db3..1b1f1fe8 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -52,7 +52,7 @@ import ( "github.com/k8stopologyawareschedwg/deployer/pkg/deployer/platform" "github.com/k8stopologyawareschedwg/deployer/pkg/deployer/wait" "github.com/k8stopologyawareschedwg/deployer/pkg/manifests" - "github.com/k8stopologyawareschedwg/deployer/pkg/manifests/sched" + schedmanifests "github.com/k8stopologyawareschedwg/deployer/pkg/manifests/sched" "github.com/k8stopologyawareschedwg/deployer/pkg/options" "github.com/k8stopologyawareschedwg/deployer/pkg/stringify" "github.com/k8stopologyawareschedwg/deployer/pkg/validator" @@ -327,7 +327,10 @@ func expectSchedulerRunning(ctx context.Context, cli client.Client) { ginkgo.By("checking that topo-aware-scheduler pod is running") // TODO: autodetect the platform - mfs, err := sched.GetManifests(platform.Kubernetes, ns.Name) + mfs, err := schedmanifests.NewWithOptions(options.Render{ + Platform: platform.Kubernetes, + Namespace: ns.Name, + }) gomega.Expect(err).ToNot(gomega.HaveOccurred()) mfs, err = mfs.Render(logr.Discard(), options.Scheduler{ Replicas: int32(1), diff --git a/test/e2e/manifests.go b/test/e2e/manifests.go index 59861ce2..5d5b7d97 100644 --- a/test/e2e/manifests.go +++ b/test/e2e/manifests.go @@ -60,7 +60,13 @@ var _ = ginkgo.Describe("[ManifestFlow] Deployer rendering", ginkgo.Label("manif gomega.Expect(err).ToNot(gomega.HaveOccurred()) enableCRIHooks := true - mf, err := rte.GetManifests(platform.Kubernetes, platform.Version("1.23"), ns.Name, enableCRIHooks, true) + mf, err := rte.NewWithOptions(options.Render{ + Platform: platform.Kubernetes, + PlatformVersion: platform.Version("1.23"), + Namespace: ns.Name, + EnableCRIHooks: enableCRIHooks, + CustomSELinuxPolicy: true, + }) gomega.Expect(err).ToNot(gomega.HaveOccurred()) mf, err = mf.Render(options.UpdaterDaemon{ Namespace: ns.Name, @@ -69,7 +75,10 @@ var _ = ginkgo.Describe("[ManifestFlow] Deployer rendering", ginkgo.Label("manif e2epods.WaitPodsToBeRunningByRegex(fmt.Sprintf("%s-*", mf.DaemonSet.Name)) ginkgo.By("checking that topo-aware-scheduler pod is running") - mfs, err := sched.GetManifests(platform.Kubernetes, ns.Name) + mfs, err := sched.NewWithOptions(options.Render{ + Platform: platform.Kubernetes, + Namespace: ns.Name, + }) gomega.Expect(err).ToNot(gomega.HaveOccurred()) mfs, err = mfs.Render(logr.Discard(), options.Scheduler{ Replicas: int32(1), diff --git a/test/e2e/negative.go b/test/e2e/negative.go index 6c5361ba..eafb3c98 100644 --- a/test/e2e/negative.go +++ b/test/e2e/negative.go @@ -98,7 +98,14 @@ var _ = ginkgo.Describe("[NegativeFlow] Deployer execution with PFP disabled", g gomega.Expect(err).ToNot(gomega.HaveOccurred()) enableCRIHooks := true - mf, err := rte.GetManifests(platform.Kubernetes, platform.Version("1.23"), ns.Name, enableCRIHooks, true) + mf, err := rte.NewWithOptions(options.Render{ + Platform: platform.Kubernetes, + PlatformVersion: platform.Version("1.23"), + Namespace: ns.Name, + EnableCRIHooks: enableCRIHooks, + CustomSELinuxPolicy: true, + }) + gomega.Expect(err).ToNot(gomega.HaveOccurred()) mf, err = mf.Render(options.UpdaterDaemon{ Namespace: ns.Name, @@ -107,7 +114,10 @@ var _ = ginkgo.Describe("[NegativeFlow] Deployer execution with PFP disabled", g e2epods.WaitPodsToBeRunningByRegex(fmt.Sprintf("%s-*", mf.DaemonSet.Name)) ginkgo.By("checking that topo-aware-scheduler pod is running") - mfs, err := sched.GetManifests(platform.Kubernetes, ns.Name) + mfs, err := sched.NewWithOptions(options.Render{ + Platform: platform.Kubernetes, + Namespace: ns.Name, + }) gomega.Expect(err).ToNot(gomega.HaveOccurred()) mfs, err = mfs.Render(logr.Discard(), options.Scheduler{ Replicas: int32(1), @@ -143,7 +153,10 @@ var _ = ginkgo.Describe("[NegativeFlow] Deployer execution with PFP disabled", g ns, err := manifests.Namespace(manifests.ComponentNodeFeatureDiscovery) gomega.Expect(err).ToNot(gomega.HaveOccurred()) - mf, err := nfd.GetManifests(platform.Kubernetes, ns.Name) + mf, err := nfd.NewWithOptions(options.Render{ + Platform: platform.Kubernetes, + Namespace: ns.Name, + }) gomega.Expect(err).ToNot(gomega.HaveOccurred()) mf, err = mf.Render(options.UpdaterDaemon{ Namespace: ns.Name, @@ -152,7 +165,10 @@ var _ = ginkgo.Describe("[NegativeFlow] Deployer execution with PFP disabled", g e2epods.WaitPodsToBeRunningByRegex(fmt.Sprintf("%s-*", mf.DSTopologyUpdater.Name)) ginkgo.By("checking that topo-aware-scheduler pod is running") - mfs, err := sched.GetManifests(platform.Kubernetes, ns.Name) + mfs, err := sched.NewWithOptions(options.Render{ + Platform: platform.Kubernetes, + Namespace: ns.Name, + }) gomega.Expect(err).ToNot(gomega.HaveOccurred()) mfs, err = mfs.Render(logr.Discard(), options.Scheduler{ Replicas: int32(1), diff --git a/test/e2e/positive.go b/test/e2e/positive.go index fe34dcff..da7f9822 100644 --- a/test/e2e/positive.go +++ b/test/e2e/positive.go @@ -245,7 +245,13 @@ var _ = ginkgo.Describe("[PositiveFlow] Deployer execution", ginkgo.Label("posit gomega.Expect(err).ToNot(gomega.HaveOccurred()) enableCRIHooks := true - mf, err := rte.GetManifests(platform.Kubernetes, platform.Version("1.23"), ns.Name, enableCRIHooks, true) + mf, err := rte.NewWithOptions(options.Render{ + Platform: platform.Kubernetes, + PlatformVersion: platform.Version("1.23"), + Namespace: ns.Name, + EnableCRIHooks: enableCRIHooks, + CustomSELinuxPolicy: true, + }) gomega.Expect(err).ToNot(gomega.HaveOccurred()) mf, err = mf.Render(options.UpdaterDaemon{ Namespace: ns.Name, @@ -254,7 +260,10 @@ var _ = ginkgo.Describe("[PositiveFlow] Deployer execution", ginkgo.Label("posit e2epods.WaitPodsToBeRunningByRegex(fmt.Sprintf("%s-*", mf.DaemonSet.Name)) ginkgo.By("checking that topo-aware-scheduler pod is running") - mfs, err := sched.GetManifests(platform.Kubernetes, ns.Name) + mfs, err := sched.NewWithOptions(options.Render{ + Platform: platform.Kubernetes, + Namespace: ns.Name, + }) gomega.Expect(err).ToNot(gomega.HaveOccurred()) mfs, err = mfs.Render(logr.Discard(), options.Scheduler{ Replicas: int32(1), @@ -331,7 +340,10 @@ var _ = ginkgo.Describe("[PositiveFlow] Deployer execution", ginkgo.Label("posit ns, err := manifests.Namespace(manifests.ComponentNodeFeatureDiscovery) gomega.Expect(err).ToNot(gomega.HaveOccurred()) - mf, err := nfd.GetManifests(platform.Kubernetes, ns.Name) + mf, err := nfd.NewWithOptions(options.Render{ + Platform: platform.Kubernetes, + Namespace: ns.Name, + }) gomega.Expect(err).ToNot(gomega.HaveOccurred()) mf, err = mf.Render(options.UpdaterDaemon{ Namespace: ns.Name, @@ -340,7 +352,10 @@ var _ = ginkgo.Describe("[PositiveFlow] Deployer execution", ginkgo.Label("posit e2epods.WaitPodsToBeRunningByRegex(fmt.Sprintf("%s-*", mf.DSTopologyUpdater.Name)) ginkgo.By("checking that topo-aware-scheduler pod is running") - mfs, err := sched.GetManifests(platform.Kubernetes, ns.Name) + mfs, err := sched.NewWithOptions(options.Render{ + Platform: platform.Kubernetes, + Namespace: ns.Name, + }) gomega.Expect(err).ToNot(gomega.HaveOccurred()) mfs, err = mfs.Render(logr.Discard(), options.Scheduler{ Replicas: int32(1), diff --git a/test/e2e/utils/dump/dump.go b/test/e2e/utils/dump/dump.go index e2eee8ee..3ba53cf3 100644 --- a/test/e2e/utils/dump/dump.go +++ b/test/e2e/utils/dump/dump.go @@ -58,7 +58,10 @@ func SchedulerPods(ctx context.Context, cli client.Client) error { } // TODO: autodetect the platform - mfs, err := sched.GetManifests(platform.Kubernetes, ns.Name) + mfs, err := sched.NewWithOptions(options.Render{ + Platform: platform.Kubernetes, + Namespace: ns.Name, + }) if err != nil { return err } @@ -143,7 +146,13 @@ func ResourceTopologyExporterPods(ctx context.Context, cli client.Client) error } // TODO: autodetect the platform - mfs, err := rte.GetManifests(platform.Kubernetes, platform.Version("1.23"), ns.Name, true, false) + mfs, err := rte.NewWithOptions(options.Render{ + Platform: platform.Kubernetes, + PlatformVersion: platform.Version("1.23"), + Namespace: ns.Name, + EnableCRIHooks: true, + CustomSELinuxPolicy: true, + }) if err != nil { return err }