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

Remove bool ptr #625

Merged
merged 2 commits into from
Feb 12, 2024
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: 2 additions & 2 deletions api/v1/sriovoperatorconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ type SriovOperatorConfigSpec struct {
// NodeSelector selects the nodes to be configured
ConfigDaemonNodeSelector map[string]string `json:"configDaemonNodeSelector,omitempty"`
// Flag to control whether the network resource injector webhook shall be deployed
EnableInjector *bool `json:"enableInjector,omitempty"`
EnableInjector bool `json:"enableInjector,omitempty"`
// Flag to control whether the operator admission controller webhook shall be deployed
EnableOperatorWebhook *bool `json:"enableOperatorWebhook,omitempty"`
EnableOperatorWebhook bool `json:"enableOperatorWebhook,omitempty"`
// Flag to control the log verbose level of the operator. Set to '0' to show only the basic logs. And set to '2' to show all the available logs.
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=2
Expand Down
10 changes: 0 additions & 10 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions controllers/sriovoperatorconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ func (r *SriovOperatorConfigReconciler) Reconcile(ctx context.Context, req ctrl.
defaultConfig.SetNamespace(vars.Namespace)
defaultConfig.SetName(consts.DefaultConfigName)
defaultConfig.Spec = sriovnetworkv1.SriovOperatorConfigSpec{
EnableInjector: func() *bool { b := vars.EnableAdmissionController; return &b }(),
EnableOperatorWebhook: func() *bool { b := vars.EnableAdmissionController; return &b }(),
EnableInjector: vars.EnableAdmissionController,
EnableOperatorWebhook: vars.EnableAdmissionController,
ConfigDaemonNodeSelector: map[string]string{},
LogLevel: 2,
DisableDrain: singleNode,
Expand Down Expand Up @@ -266,7 +266,7 @@ func (r *SriovOperatorConfigReconciler) syncWebhookObjs(ctx context.Context, dc
}

// Delete injector webhook
if !*dc.Spec.EnableInjector && path == consts.InjectorWebHookPath {
if !dc.Spec.EnableInjector && path == consts.InjectorWebHookPath {
for _, obj := range objs {
err = r.deleteWebhookObject(ctx, obj)
if err != nil {
Expand All @@ -279,7 +279,7 @@ func (r *SriovOperatorConfigReconciler) syncWebhookObjs(ctx context.Context, dc
continue
}
// Delete operator webhook
if !*dc.Spec.EnableOperatorWebhook && path == consts.OperatorWebHookPath {
if !dc.Spec.EnableOperatorWebhook && path == consts.OperatorWebHookPath {
for _, obj := range objs {
err = r.deleteWebhookObject(ctx, obj)
if err != nil {
Expand Down
16 changes: 8 additions & 8 deletions controllers/sriovoperatorconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ var _ = Describe("SriovOperatorConfig controller", Ordered, func() {
config.SetNamespace(testNamespace)
config.SetName(constants.DefaultConfigName)
config.Spec = sriovnetworkv1.SriovOperatorConfigSpec{
EnableInjector: func() *bool { b := true; return &b }(),
EnableOperatorWebhook: func() *bool { b := true; return &b }(),
EnableInjector: true,
EnableOperatorWebhook: true,
ConfigDaemonNodeSelector: map[string]string{},
LogLevel: 2,
}
Expand Down Expand Up @@ -100,8 +100,8 @@ var _ = Describe("SriovOperatorConfig controller", Ordered, func() {
err := util.WaitForNamespacedObject(config, k8sClient, testNamespace, "default", util.RetryInterval, util.APITimeout)
Expect(err).NotTo(HaveOccurred())
config.Spec = sriovnetworkv1.SriovOperatorConfigSpec{
EnableInjector: func() *bool { b := true; return &b }(),
EnableOperatorWebhook: func() *bool { b := true; return &b }(),
EnableInjector: true,
EnableOperatorWebhook: true,
// ConfigDaemonNodeSelector: map[string]string{},
LogLevel: 2,
}
Expand Down Expand Up @@ -137,7 +137,7 @@ var _ = Describe("SriovOperatorConfig controller", Ordered, func() {
err := util.WaitForNamespacedObject(config, k8sClient, testNamespace, "default", util.RetryInterval, util.APITimeout)
Expect(err).NotTo(HaveOccurred())

*config.Spec.EnableInjector = false
config.Spec.EnableInjector = false
err = k8sClient.Update(ctx, config)
Expect(err).NotTo(HaveOccurred())

Expand All @@ -153,7 +153,7 @@ var _ = Describe("SriovOperatorConfig controller", Ordered, func() {
err = util.WaitForNamespacedObject(config, k8sClient, testNamespace, "default", util.RetryInterval, util.APITimeout)
Expect(err).NotTo(HaveOccurred())

*config.Spec.EnableInjector = true
config.Spec.EnableInjector = true
err = k8sClient.Update(ctx, config)
Expect(err).NotTo(HaveOccurred())

Expand All @@ -173,7 +173,7 @@ var _ = Describe("SriovOperatorConfig controller", Ordered, func() {
err := util.WaitForNamespacedObject(config, k8sClient, testNamespace, "default", util.RetryInterval, util.APITimeout)
Expect(err).NotTo(HaveOccurred())

*config.Spec.EnableOperatorWebhook = false
config.Spec.EnableOperatorWebhook = false
err = k8sClient.Update(ctx, config)
Expect(err).NotTo(HaveOccurred())

Expand All @@ -193,7 +193,7 @@ var _ = Describe("SriovOperatorConfig controller", Ordered, func() {
err = util.WaitForNamespacedObject(config, k8sClient, testNamespace, "default", util.RetryInterval, util.APITimeout)
Expect(err).NotTo(HaveOccurred())

*config.Spec.EnableOperatorWebhook = true
config.Spec.EnableOperatorWebhook = true
err = k8sClient.Update(ctx, config)
Expect(err).NotTo(HaveOccurred())

Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,8 @@ func createDefaultOperatorConfig(c client.Client) error {
enableAdmissionController := os.Getenv("ADMISSION_CONTROLLERS_ENABLED") == "true"
config := &sriovnetworkv1.SriovOperatorConfig{
Spec: sriovnetworkv1.SriovOperatorConfigSpec{
EnableInjector: func() *bool { b := enableAdmissionController; return &b }(),
EnableOperatorWebhook: func() *bool { b := enableAdmissionController; return &b }(),
EnableInjector: enableAdmissionController,
EnableOperatorWebhook: enableAdmissionController,
ConfigDaemonNodeSelector: map[string]string{},
LogLevel: 2,
DisableDrain: singleNode,
Expand Down
4 changes: 2 additions & 2 deletions pkg/webhook/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ func newDefaultOperatorConfig() *SriovOperatorConfig {
Spec: SriovOperatorConfigSpec{
ConfigDaemonNodeSelector: map[string]string{},
DisableDrain: true,
EnableInjector: func() *bool { b := true; return &b }(),
EnableOperatorWebhook: func() *bool { b := true; return &b }(),
EnableInjector: true,
EnableOperatorWebhook: true,
LogLevel: 2,
},
}
Expand Down
12 changes: 6 additions & 6 deletions test/conformance/tests/test_sriov_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2560,18 +2560,18 @@ func setSriovOperatorSpecFlag(flagName string, flagValue bool) {
}, &cfg)

Expect(err).ToNot(HaveOccurred())
if flagName == operatorNetworkInjectorFlag && *cfg.Spec.EnableInjector != flagValue {
cfg.Spec.EnableInjector = &flagValue
if flagName == operatorNetworkInjectorFlag && cfg.Spec.EnableInjector != flagValue {
cfg.Spec.EnableInjector = flagValue
err = clients.Update(context.TODO(), &cfg)
Expect(err).ToNot(HaveOccurred())
Expect(*cfg.Spec.EnableInjector).To(Equal(flagValue))
Expect(cfg.Spec.EnableInjector).To(Equal(flagValue))
}

if flagName == operatorWebhookFlag && *cfg.Spec.EnableOperatorWebhook != flagValue {
cfg.Spec.EnableOperatorWebhook = &flagValue
if flagName == operatorWebhookFlag && cfg.Spec.EnableOperatorWebhook != flagValue {
cfg.Spec.EnableOperatorWebhook = flagValue
clients.Update(context.TODO(), &cfg)
Expect(err).ToNot(HaveOccurred())
Expect(*cfg.Spec.EnableOperatorWebhook).To(Equal(flagValue))
Expect(cfg.Spec.EnableOperatorWebhook).To(Equal(flagValue))
}

if flagValue {
Expand Down
4 changes: 2 additions & 2 deletions test/validation/tests/test_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ var _ = Describe("validation", func() {
err := clients.Client.Get(context.TODO(), goclient.ObjectKey{Name: "default", Namespace: operatorNamespace}, operatorConfig)
Expect(err).ToNot(HaveOccurred())

if *operatorConfig.Spec.EnableInjector {
if operatorConfig.Spec.EnableInjector {
daemonset, err := clients.DaemonSets(operatorNamespace).Get(context.Background(), "network-resources-injector", metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(daemonset.Status.DesiredNumberScheduled).To(Equal(daemonset.Status.NumberReady))
Expand All @@ -103,7 +103,7 @@ var _ = Describe("validation", func() {
err := clients.Get(context.TODO(), goclient.ObjectKey{Name: "default", Namespace: operatorNamespace}, operatorConfig)
Expect(err).ToNot(HaveOccurred())

if *operatorConfig.Spec.EnableOperatorWebhook {
if operatorConfig.Spec.EnableOperatorWebhook {
daemonset, err := clients.DaemonSets(operatorNamespace).Get(context.Background(), "operator-webhook", metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(daemonset.Status.DesiredNumberScheduled).To(Equal(daemonset.Status.NumberReady))
Expand Down
Loading