From 26f9c66745f75c1d652c93c7bbd98d42d7e82ed3 Mon Sep 17 00:00:00 2001 From: Jan Baraniewski Date: Tue, 3 May 2022 22:12:21 +0200 Subject: [PATCH] Make manager optional in legacy config + some fixes --- .../app.kubeserial.com_kubeserials.yaml | 1 - pkg/apis/kubeserial/v1alpha1/kubeserial.go | 16 ++++++++++--- .../v1alpha1/zz_generated.openapi.go | 2 +- pkg/controllers/device_controller.go | 24 +++++-------------- pkg/monitor/ds.go | 2 +- 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/deploy/chart/kubeserial-crds/templates/app.kubeserial.com_kubeserials.yaml b/deploy/chart/kubeserial-crds/templates/app.kubeserial.com_kubeserials.yaml index 047294e6..4a80f98e 100644 --- a/deploy/chart/kubeserial-crds/templates/app.kubeserial.com_kubeserials.yaml +++ b/deploy/chart/kubeserial-crds/templates/app.kubeserial.com_kubeserials.yaml @@ -48,7 +48,6 @@ spec: required: - idProduct - idVendor - - manager - name - subsystem type: object diff --git a/pkg/apis/kubeserial/v1alpha1/kubeserial.go b/pkg/apis/kubeserial/v1alpha1/kubeserial.go index 5f5d7fc9..91aad4c2 100644 --- a/pkg/apis/kubeserial/v1alpha1/kubeserial.go +++ b/pkg/apis/kubeserial/v1alpha1/kubeserial.go @@ -23,10 +23,20 @@ import ( // Device defines monitored device // +k8s:openapi-gen=true type Device_2 struct { - Name string `json:"name"` - IdVendor string `json:"idVendor"` + // +required + // +kubebuilder:validation:Required + Name string `json:"name"` + // +required + // +kubebuilder:validation:Required + IdVendor string `json:"idVendor"` + // +required + // +kubebuilder:validation:Required IdProduct string `json:"idProduct"` - Manager string `json:"manager"` + // +optional + // +kubebuilder:validation:Optional + Manager string `json:"manager"` + // +required + // +kubebuilder:validation:Required Subsystem string `json:"subsystem"` } diff --git a/pkg/apis/kubeserial/v1alpha1/zz_generated.openapi.go b/pkg/apis/kubeserial/v1alpha1/zz_generated.openapi.go index 2e12bfe5..70efa55c 100644 --- a/pkg/apis/kubeserial/v1alpha1/zz_generated.openapi.go +++ b/pkg/apis/kubeserial/v1alpha1/zz_generated.openapi.go @@ -169,7 +169,7 @@ func schema_pkg_apis_kubeserial_v1alpha1_Device_2(ref common.ReferenceCallback) }, }, }, - Required: []string{"name", "idVendor", "idProduct", "manager", "subsystem"}, + Required: []string{"name", "idVendor", "idProduct", "subsystem"}, }, }, } diff --git a/pkg/controllers/device_controller.go b/pkg/controllers/device_controller.go index 61befb75..8fbf6087 100644 --- a/pkg/controllers/device_controller.go +++ b/pkg/controllers/device_controller.go @@ -96,26 +96,14 @@ func (r *DeviceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr // EnsureConditions makes sure all conditions are available in resource func (r *DeviceReconciler) EnsureConditions(ctx context.Context, device *kubeserialv1alpha1.Device) error { logger := devLog.WithName("EnsureConditions") - for _, condition := range []struct { - Type kubeserialv1alpha1.DeviceConditionType - IsNeeded func() bool - }{ - { - Type: kubeserialv1alpha1.DeviceAvailable, - IsNeeded: func() bool { return true }, - }, - { - Type: kubeserialv1alpha1.DeviceReady, - IsNeeded: device.NeedsManager, - }, + for _, conditionType := range []kubeserialv1alpha1.DeviceConditionType{ + kubeserialv1alpha1.DeviceAvailable, + kubeserialv1alpha1.DeviceReady, } { - if !condition.IsNeeded() { - continue - } - if utils.GetCondition(device.Status.Conditions, condition.Type) == nil { - logger.Info("Condition didn't exist, creating", "conditionType", condition.Type) + if utils.GetCondition(device.Status.Conditions, conditionType) == nil { + logger.Info("Condition didn't exist, creating", "conditionType", conditionType) utils.SetDeviceCondition(&device.Status.Conditions, kubeserialv1alpha1.DeviceCondition{ - Type: condition.Type, + Type: conditionType, Status: v1.ConditionUnknown, Reason: "NotValidated", }) diff --git a/pkg/monitor/ds.go b/pkg/monitor/ds.go index 18b72a96..991def62 100644 --- a/pkg/monitor/ds.go +++ b/pkg/monitor/ds.go @@ -83,7 +83,7 @@ func CreateDaemonSet(cr *appv1alpha1.KubeSerial, monitorVersion string) *appsv1. Command: []string{"/bin/sh"}, Args: []string{ "-c", - "./bin/device-monitor", + "./go/bin/device-monitor", }, Env: []corev1.EnvVar{ {