Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updaters: add toggle to deploy CRI hooks #197

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/commands/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func NewRemoveCommand(commonOpts *CommonOptions) *cobra.Command {
WaitCompletion: opts.waitCompletion,
RTEConfigData: commonOpts.RTEConfigData,
DaemonSet: daemonSetOptionsFromCommonOptions(commonOpts),
EnableCRIHooks: commonOpts.UpdaterCRIHooksEnable,
})
if err != nil {
// intentionally keep going to remove as much as possible
Expand Down Expand Up @@ -220,6 +221,7 @@ func NewDeployTopologyUpdaterCommand(commonOpts *CommonOptions, opts *DeployOpti
WaitCompletion: opts.waitCompletion,
RTEConfigData: commonOpts.RTEConfigData,
DaemonSet: daemonSetOptionsFromCommonOptions(commonOpts),
EnableCRIHooks: commonOpts.UpdaterCRIHooksEnable,
})
},
Args: cobra.NoArgs,
Expand Down Expand Up @@ -329,6 +331,7 @@ func NewRemoveTopologyUpdaterCommand(commonOpts *CommonOptions, opts *DeployOpti
WaitCompletion: opts.waitCompletion,
RTEConfigData: commonOpts.RTEConfigData,
DaemonSet: daemonSetOptionsFromCommonOptions(commonOpts),
EnableCRIHooks: commonOpts.UpdaterCRIHooksEnable,
})
},
Args: cobra.NoArgs,
Expand Down Expand Up @@ -367,6 +370,7 @@ func deployOnCluster(commonOpts *CommonOptions, opts *DeployOptions) error {
WaitCompletion: opts.waitCompletion,
RTEConfigData: commonOpts.RTEConfigData,
DaemonSet: daemonSetOptionsFromCommonOptions(commonOpts),
EnableCRIHooks: commonOpts.UpdaterCRIHooksEnable,
}); err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/commands/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func makeUpdaterObjects(commonOpts *CommonOptions) ([]client.Object, string, err
Platform: commonOpts.UserPlatform,
RTEConfigData: commonOpts.RTEConfigData,
DaemonSet: daemonSetOptionsFromCommonOptions(commonOpts),
EnableCRIHooks: commonOpts.UpdaterCRIHooksEnable,
}
objs, err := updaters.GetObjects(opts, commonOpts.UpdaterType, namespace)
if err != nil {
Expand Down
38 changes: 20 additions & 18 deletions pkg/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,25 @@ const (
)

type CommonOptions struct {
Debug bool
UserPlatform platform.Platform
UserPlatformVersion platform.Version
Log logr.Logger
DebugLog logr.Logger
Replicas int
RTEConfigData string
PullIfNotPresent bool
UpdaterType string
UpdaterPFPEnable bool
UpdaterNotifEnable bool
UpdaterSyncPeriod time.Duration
UpdaterVerbose int
SchedProfileName string
SchedResyncPeriod time.Duration
rteConfigFile string
plat string
platVer string
Debug bool
UserPlatform platform.Platform
UserPlatformVersion platform.Version
Log logr.Logger
DebugLog logr.Logger
Replicas int
RTEConfigData string
PullIfNotPresent bool
UpdaterType string
UpdaterPFPEnable bool
UpdaterNotifEnable bool
UpdaterCRIHooksEnable bool
UpdaterSyncPeriod time.Duration
UpdaterVerbose int
SchedProfileName string
SchedResyncPeriod time.Duration
rteConfigFile string
plat string
platVer string
}

func ShowHelp(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -116,6 +117,7 @@ func InitFlags(flags *pflag.FlagSet, commonOpts *CommonOptions) {
flags.StringVar(&commonOpts.UpdaterType, "updater-type", "RTE", "type of updater to deploy - RTE or NFD")
flags.BoolVar(&commonOpts.UpdaterPFPEnable, "updater-pfp-enable", true, "toggle PFP support on the updater side.")
flags.BoolVar(&commonOpts.UpdaterNotifEnable, "updater-notif-enable", true, "toggle event-based notification support on the updater side.")
flags.BoolVar(&commonOpts.UpdaterCRIHooksEnable, "updater-cri-hooks-enable", true, "toggle installation of CRI hooks on the updater side.")
flags.DurationVar(&commonOpts.UpdaterSyncPeriod, "updater-sync-period", DefaultUpdaterSyncPeriod, "tune the updater synchronization (nrt update) interval. Use 0 to disable.")
flags.IntVar(&commonOpts.UpdaterVerbose, "updater-verbose", 1, "set the updater verbosiness.")
flags.StringVar(&commonOpts.SchedProfileName, "sched-profile-name", DefaultSchedulerProfileName, "inject scheduler profile name.")
Expand Down
6 changes: 3 additions & 3 deletions pkg/deployer/updaters/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
func GetObjects(opts Options, updaterType, namespace string) ([]client.Object, error) {

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

func getCreatableObjects(env *deployer.Environment, opts Options, updaterType, namespace string) ([]deployer.WaitableObject, error) {
if updaterType == RTE {
mf, err := rtemanifests.GetManifests(opts.Platform, opts.PlatformVersion, namespace)
mf, err := rtemanifests.GetManifests(opts.Platform, opts.PlatformVersion, namespace, opts.EnableCRIHooks)
if err != nil {
return nil, err
}
Expand All @@ -81,7 +81,7 @@ func getCreatableObjects(env *deployer.Environment, opts Options, updaterType, n

func getDeletableObjects(env *deployer.Environment, opts Options, updaterType, namespace string) ([]deployer.WaitableObject, error) {
if updaterType == RTE {
mf, err := rtemanifests.GetManifests(opts.Platform, opts.PlatformVersion, namespace)
mf, err := rtemanifests.GetManifests(opts.Platform, opts.PlatformVersion, namespace, opts.EnableCRIHooks)
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 @@ -40,6 +40,7 @@ type Options struct {
WaitCompletion bool
RTEConfigData string
DaemonSet objectupdate.DaemonSetOptions
EnableCRIHooks bool
}

func Deploy(env *deployer.Environment, updaterType string, opts Options) error {
Expand Down
66 changes: 31 additions & 35 deletions pkg/manifests/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ func DaemonSet(component, subComponent string, namespace string) (*appsv1.Daemon
return ds, nil
}

func MachineConfig(component string, ver platform.Version) (*machineconfigv1.MachineConfig, error) {
func MachineConfig(component string, ver platform.Version, withCRIHooks bool) (*machineconfigv1.MachineConfig, error) {
if component != ComponentResourceTopologyExporter {
return nil, fmt.Errorf("component %q is not an %q component", component, ComponentResourceTopologyExporter)
}
Expand All @@ -322,7 +322,7 @@ func MachineConfig(component string, ver platform.Version) (*machineconfigv1.Mac
return nil, fmt.Errorf("unexpected type, got %t", obj)
}

ignitionConfig, err := getIgnitionConfig(ver)
ignitionConfig, err := makeIgnitionConfig(ver, withCRIHooks)
if err != nil {
return nil, err
}
Expand All @@ -331,42 +331,43 @@ func MachineConfig(component string, ver platform.Version) (*machineconfigv1.Mac
return mc, nil
}

func getIgnitionConfig(ver platform.Version) ([]byte, error) {
func makeIgnitionConfig(ver platform.Version, withCRIHooks bool) ([]byte, error) {
var files []igntypes.File

// get SELinux policy
if withCRIHooks {
// load RTE notifier OCI hook config
notifierHookConfigContent, err := getTemplateContent(rteassets.HookConfigRTENotifier, map[string]string{
templateNotifierBinaryDst: filepath.Join(defaultScriptsDir, rteassets.NotifierScriptName),
templateNotifierFilePath: filepath.Join(rteassets.HostNotifierDir, rteassets.NotifierFileName),
})
if err != nil {
return nil, err
}
files = addFileToIgnitionConfig(
files,
notifierHookConfigContent,
0644,
filepath.Join(defaultOCIHooksDir, rteassets.NotifierOCIHookConfig),
)

// load RTE notifier script
files = addFileToIgnitionConfig(
files,
rteassets.NotifierScript,
0755,
filepath.Join(defaultScriptsDir, rteassets.NotifierScriptName),
)
}

// we always need the SELinux policy
selinuxPolicy, err := selinuxassets.GetPolicy(ver)
if err != nil {
return nil, err
}

// load SELinux policy
files = addFileToIgnitionConfig(files, selinuxPolicy, 0644, selinuxassets.RTEPolicyFileName)

// load RTE notifier OCI hook config
notifierHookConfigContent, err := getTemplateContent(rteassets.HookConfigRTENotifier, map[string]string{
templateNotifierBinaryDst: filepath.Join(defaultScriptsDir, rteassets.NotifierScriptName),
templateNotifierFilePath: filepath.Join(rteassets.HostNotifierDir, rteassets.NotifierFileName),
})
if err != nil {
return nil, err
}
files = addFileToIgnitionConfig(
files,
notifierHookConfigContent,
0644,
filepath.Join(defaultOCIHooksDir, rteassets.NotifierOCIHookConfig),
)

// load RTE notifier script
files = addFileToIgnitionConfig(
files,
rteassets.NotifierScript,
0755,
filepath.Join(defaultScriptsDir, rteassets.NotifierScriptName),
)

// load systemd service to install SELinux policy
// and while we (always) need the SELinuc policy, we also need to make sure it's installed
systemdServiceContent, err := getTemplateContent(
selinuxassets.InstallSystemdServiceTemplate,
map[string]string{
Expand All @@ -393,12 +394,7 @@ func getIgnitionConfig(ver platform.Version) ([]byte, error) {
},
}

rawIgnition, err := json.Marshal(ignitionConfig)
if err != nil {
return nil, err
}

return rawIgnition, nil
return json.Marshal(ignitionConfig)
}

func addFileToIgnitionConfig(files []igntypes.File, fileContent []byte, mode int, fileDst string) []igntypes.File {
Expand Down
12 changes: 11 additions & 1 deletion pkg/manifests/manifests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ func TestMachineConfig(t *testing.T) {
type testCase struct {
name string
platformVersion platform.Version
enableCRIHooks bool
expectedFileNum int
expectedUnitNum int
}
Expand All @@ -461,20 +462,29 @@ func TestMachineConfig(t *testing.T) {
{
name: "OCP 4.10",
platformVersion: "v4.10",
enableCRIHooks: true,
expectedFileNum: 3,
expectedUnitNum: 1,
},
{
name: "OCP 4.11",
platformVersion: "v4.11",
enableCRIHooks: true,
expectedFileNum: 3,
expectedUnitNum: 1,
},
{
name: "OCP 4.11",
platformVersion: "v4.11",
enableCRIHooks: false,
expectedFileNum: 1,
expectedUnitNum: 1,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
mc, err := MachineConfig(ComponentResourceTopologyExporter, platform.Version(tc.platformVersion))
mc, err := MachineConfig(ComponentResourceTopologyExporter, platform.Version(tc.platformVersion), tc.enableCRIHooks)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/manifests/rte/rte.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,12 @@ func New(plat platform.Platform) Manifests {
return mf
}

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

if plat == platform.OpenShift {
mf.MachineConfig, err = manifests.MachineConfig(manifests.ComponentResourceTopologyExporter, version)
mf.MachineConfig, err = manifests.MachineConfig(manifests.ComponentResourceTopologyExporter, version, withCRIHooks)
if err != nil {
return mf, err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/manifests/rte/rte_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestClone(t *testing.T) {
}

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

if &cMf == &tc.mf {
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestRender(t *testing.T) {
}

for _, tc := range testCases {
tc.mf, _ = GetManifests(tc.plat, tc.platVersion, "")
tc.mf, _ = GetManifests(tc.plat, tc.platVersion, "", true)
mfBeforeRender := tc.mf.Clone()
uMf, err := tc.mf.Render(RenderOptions{})
if err != nil {
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestGetManifestsOpenShift(t *testing.T) {
},
}
for _, tc := range testCases {
mf, err := GetManifests(tc.plat, tc.platVersion, "test")
mf, err := GetManifests(tc.plat, tc.platVersion, "test", true)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/negative.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ var _ = ginkgo.Describe("[NegativeFlow] Deployer execution with PFP disabled", f
ns, err := manifests.Namespace(manifests.ComponentResourceTopologyExporter)
gomega.Expect(err).ToNot(gomega.HaveOccurred())

mf, err := rte.GetManifests(platform.Kubernetes, platform.Version("1.23"), ns.Name)
enableCRIHooks := true
mf, err := rte.GetManifests(platform.Kubernetes, platform.Version("1.23"), ns.Name, enableCRIHooks)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
mf, err = mf.Render(rte.RenderOptions{
Namespace: ns.Name,
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/positive.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ var _ = ginkgo.Describe("[PositiveFlow] Deployer execution", func() {
ns, err := manifests.Namespace(manifests.ComponentResourceTopologyExporter)
gomega.Expect(err).ToNot(gomega.HaveOccurred())

mf, err := rte.GetManifests(platform.Kubernetes, platform.Version("1.23"), ns.Name)
enableCRIHooks := true
mf, err := rte.GetManifests(platform.Kubernetes, platform.Version("1.23"), ns.Name, enableCRIHooks)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
mf, err = mf.Render(rte.RenderOptions{
Namespace: ns.Name,
Expand Down