Skip to content

Commit

Permalink
Make manager optional in legacy config + some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
janekbaraniewski committed May 3, 2022
1 parent 073c3af commit 26f9c66
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ spec:
required:
- idProduct
- idVendor
- manager
- name
- subsystem
type: object
Expand Down
16 changes: 13 additions & 3 deletions pkg/apis/kubeserial/v1alpha1/kubeserial.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/kubeserial/v1alpha1/zz_generated.openapi.go

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

24 changes: 6 additions & 18 deletions pkg/controllers/device_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/monitor/ds.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down

0 comments on commit 26f9c66

Please sign in to comment.