Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
janekbaraniewski committed Jun 22, 2022
1 parent c0849a9 commit 26c0e59
Show file tree
Hide file tree
Showing 40 changed files with 590 additions and 258 deletions.
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
linters:
enable-all: true
disable:
- cyclop # remove
- errcheck
- exhaustruct
- exhaustivestruct
Expand All @@ -9,11 +10,15 @@ linters:
- gochecknoglobals
- gochecknoinits
- gomnd
- gosec
- ireturn
- lll
- maligned
- nestif # remove
- nlreturn
- nonamedreturns # fix maybe?
- paralleltest # TODO: fix
- scopelint
- testpackage # TODO: remove this
- varnamelen
- wrapcheck
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ spec:
- name: v1alpha1
schema:
openAPIV3Schema:
description: Manager is the Schema for the managers API
description: Manager is the Schema for the managers API.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
Expand All @@ -29,14 +29,14 @@ spec:
metadata:
type: object
spec:
description: ManagerSpec defines the desired state of Manager
description: ManagerSpec defines the desired state of Manager.
properties:
config:
type: string
configPath:
type: string
image:
description: Image is spec for image to be used by manager
description: Image is spec for image to be used by manager.
properties:
repository:
type: string
Expand All @@ -53,7 +53,7 @@ spec:
- runCmd
type: object
status:
description: ManagerStatus defines the observed state of Manager
description: ManagerStatus defines the observed state of Manager.
type: object
type: object
served: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ spec:
name: v1alpha1
schema:
openAPIV3Schema:
description: ManagerScheduleRequest is the Schema for the managerschedulerequests API
description: ManagerScheduleRequest is the Schema for the managerschedulerequests API.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
Expand All @@ -39,7 +39,7 @@ spec:
metadata:
type: object
spec:
description: ManagerScheduleRequestSpec defines the desired state of ManagerScheduleRequest
description: ManagerScheduleRequestSpec defines the desired state of ManagerScheduleRequest.
properties:
device:
type: string
Expand All @@ -50,7 +50,7 @@ spec:
- manager
type: object
status:
description: ManagerScheduleRequestStatus defines the observed state of ManagerScheduleRequest
description: ManagerScheduleRequestStatus defines the observed state of ManagerScheduleRequest.
properties:
fulfilled:
default: false
Expand Down
4 changes: 2 additions & 2 deletions charts/kubeserial/templates/serialdevices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ metadata:
labels:
{{- include "kubeserial.labels" $ | nindent 4 }}
spec:
idProduct: {{ .idProduct | quote }}
idVendor: {{ .idVendor | quote }}
IDProduct: {{ .IDProduct | quote }}
IDVendor: {{ .IDVendor | quote }}
name: {{ .name | quote }}
manager: {{ .manager | quote }}
---
Expand Down
1 change: 0 additions & 1 deletion cmd/device-monitor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func main() {
log.Info("Start setup")

_, err := metrics.NewListener(":8080")

if err != nil {
log.Info("Failed setting up metrics listener")
}
Expand Down
9 changes: 7 additions & 2 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@ func main() {
)
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.StringVar(&deviceMonitorVersion, "device-monitor-version", "latest", "Version of kubeserial-device-monitor image to be used")
flag.StringVar(
&deviceMonitorVersion,
"device-monitor-version",
"latest",
"Version of kubeserial-device-monitor image to be used",
)
flag.StringVar(&namespace, "namespace", "kubeserial", "Kubernetes Namespace in which controllers are running")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
Expand Down Expand Up @@ -90,7 +95,7 @@ func main() {
fs := utils.NewOSFS()
client := mgr.GetClient()
scheme := mgr.GetScheme()
apiClient := kubeapi.NewApiClient(client, scheme)
apiClient := kubeapi.NewAPIClient(client, scheme)

if err = (&controllers.KubeSerialReconciler{
Client: client,
Expand Down
1 change: 0 additions & 1 deletion cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func main() {
hookServer.CertDir = params.certDir

config, err := rest.InClusterConfig()

if err != nil {
entryLog.Error(err, "Failed to get InClusterConfig")
panic(err.Error())
Expand Down
17 changes: 8 additions & 9 deletions docs/src/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
First you'll need to add helm repository that stores KubeSerial charts

```bash
$ helm repo add baraniewski https://baraniewski.com/charts/
> helm repo add baraniewski https://baraniewski.com/charts/
```

### Install CRDs

Due to way in which helm handles CRDs, they are managed using separate chart.

```bash
$ helm upgrade --install kubeserial-crds baraniewski/kubeserial-crds
> helm upgrade --install kubeserial-crds baraniewski/kubeserial-crds
```

### Create minimal values file
Expand All @@ -40,15 +40,15 @@ certManagerIssuer:
### Install Controller
```bash
$ helm upgrade --install kubeserial baraniewski/kubeserial
> helm upgrade --install kubeserial baraniewski/kubeserial
```

## Get device attributes

To find out values of `idVendor` and `idProduct` for your device, connect it to your computer, locate where it is (let's say `/dev/ttyUSB0`) and run:

```bash
udevadm info -q all -n /dev/ttyUSB0 --attribute-walk
> udevadm info -q all -n /dev/ttyUSB0 --attribute-walk
```

Look for them from the top.
Expand All @@ -59,7 +59,6 @@ Now you're ready to create configuration for your devices. Here you can find exa

Add this config to your values file:


```yaml
kubeserial:
serialDevices:
Expand All @@ -75,15 +74,15 @@ kubeserial:
## Update your helm release with new values
```bash
$ helm upgrade kubeserial baraniewski/kubeserial -f my-values.yaml
> helm upgrade kubeserial baraniewski/kubeserial -f my-values.yaml
```

## Validate that everything is working

You should see 3 workloads in your cluster - controler manager, device injector webhook and device monitor:

```bash
$ ➜ kubectl get pods
$ ➜ kubectl get pods
NAME READY STATUS RESTARTS AGE
kubeserial-7d58555d4c-97nqk 1/1 Running 0 5m
kubeserial-device-injector-cc7696b59-mfdn5 1/1 Running 0 5m
Expand All @@ -97,8 +96,8 @@ You should also see your devices:
```bash
$ ➜ kubectl get serialdevice
NAME READY AVAILABLE NODE
ender3 True False
sonoff-zigbee True False
ender3 True False
sonoff-zigbee True False
```

You're all set with basic configuration of KubeSerial. Please read through rest of docs to configure it to your needs.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ require (
github.com/fatih/color v1.13.0 // indirect
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/logr v1.2.3
github.com/go-logr/zapr v1.2.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
Expand Down
10 changes: 5 additions & 5 deletions pkg/apis/v1alpha1/kubeserial.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ import (

// SerialDevice defines monitored device
// +k8s:openapi-gen=true
type SerialDevice_2 struct {
type SerialDevice2 struct {
// +required
// +kubebuilder:validation:Required
Name string `json:"name"`
// +required
// +kubebuilder:validation:Required
IdVendor string `json:"idVendor"`
IDVendor string `json:"idVendor"`
// +required
// +kubebuilder:validation:Required
IdProduct string `json:"idProduct"`
IDProduct string `json:"idProduct"`
// +optional
// +kubebuilder:validation:Optional
Manager string `json:"manager"`
Expand All @@ -56,7 +56,7 @@ type IngressSpec struct {
type KubeSerialSpec struct {
// +required
// +kubebuilder:validation:Required
SerialDevices []SerialDevice_2 `json:"serialDevices"`
SerialDevices []SerialDevice2 `json:"serialDevices"`
// +required
// +kubebuilder:validation:Required
Ingress IngressSpec `json:"ingress"`
Expand All @@ -83,7 +83,7 @@ type KubeSerial struct {

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// KubeSerialList contains a list of KubeSerial
// KubeSerialList contains a list of KubeSerial.
type KubeSerialList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
10 changes: 5 additions & 5 deletions pkg/apis/v1alpha1/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// Image is spec for image to be used by manager
// Image is spec for image to be used by manager.
type Image struct {
// +required
// +kubebuilder:validation:Required
Expand All @@ -31,7 +31,7 @@ type Image struct {
}

// +k8s:openapi-gen=true
// ManagerSpec defines the desired state of Manager
// ManagerSpec defines the desired state of Manager.
type ManagerSpec struct {
// +required
// +kubebuilder:validation:Required
Expand All @@ -48,7 +48,7 @@ type ManagerSpec struct {
}

// +k8s:openapi-gen=true
// ManagerStatus defines the observed state of Manager
// ManagerStatus defines the observed state of Manager.
type ManagerStatus struct{}

// +genclient
Expand All @@ -59,7 +59,7 @@ type ManagerStatus struct{}
// +kubebuilder:resource:path=managers,scope=Cluster
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// Manager is the Schema for the managers API
// Manager is the Schema for the managers API.
type Manager struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -71,7 +71,7 @@ type Manager struct {
//+kubebuilder:object:root=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ManagerList contains a list of Manager
// ManagerList contains a list of Manager.
type ManagerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/v1alpha1/managerschedulerequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

// +k8s:openapi-gen=true
// ManagerScheduleRequestSpec defines the desired state of ManagerScheduleRequest
// ManagerScheduleRequestSpec defines the desired state of ManagerScheduleRequest.
type ManagerScheduleRequestSpec struct {
// +kubebuilder:validation:Required
Device string `json:"device"`
Expand All @@ -30,7 +30,7 @@ type ManagerScheduleRequestSpec struct {
}

// +k8s:openapi-gen=true
// ManagerScheduleRequestStatus defines the observed state of ManagerScheduleRequest
// ManagerScheduleRequestStatus defines the observed state of ManagerScheduleRequest.
type ManagerScheduleRequestStatus struct {
// +kubebuilder:default:=false
Fulfilled bool `json:"fulfilled"` // TODO: this is still empty when created
Expand All @@ -47,7 +47,7 @@ type ManagerScheduleRequestStatus struct {
// +kubebuilder:resource:path=managerschedulerequests,scope=Cluster
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ManagerScheduleRequest is the Schema for the managerschedulerequests API
// ManagerScheduleRequest is the Schema for the managerschedulerequests API.
type ManagerScheduleRequest struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -59,7 +59,7 @@ type ManagerScheduleRequest struct {
//+kubebuilder:object:root=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// ManagerScheduleRequestList contains a list of ManagerScheduleRequest
// ManagerScheduleRequestList contains a list of ManagerScheduleRequest.
type ManagerScheduleRequestList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
Loading

0 comments on commit 26c0e59

Please sign in to comment.