Skip to content

Commit

Permalink
Fix issues highlighted by linters (#373)
Browse files Browse the repository at this point in the history
Most of these were extraneous whitespace or lack of newlines.
  • Loading branch information
thunderboltsid authored Jan 26, 2024
1 parent cca8316 commit c075eb4
Show file tree
Hide file tree
Showing 51 changed files with 110 additions and 98 deletions.
3 changes: 1 addition & 2 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
codecov:
require_ci_to_pass: yes
require_ci_to_pass: true

ignore:
# ignore all generated controller-gen and conversion-gen code
Expand All @@ -13,4 +13,3 @@ coverage:
patch:
default:
target: 75%

6 changes: 3 additions & 3 deletions .github/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ changelog:
- Semver-Minor
- enhancement
- title: Bug Fixes 🐛
labels:
labels:
- bug
- title: Documentation 📖
labels:
labels:
- documentation
- title: Other Changes
labels:
- "*"
- "*"
14 changes: 11 additions & 3 deletions .github/workflows/build-dev.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Test Build
name: Build, Lint, and Test
env:
EXPORT_RESULT: true
on:
push:
branches: [ "main" ]
branches: ["main"]
pull_request:
branches: [ "main" ]
branches: ["main"]
jobs:
build-container:
runs-on: ubuntu-latest
Expand All @@ -27,6 +27,14 @@ jobs:
- name: Build
run: make generate fmt vet build

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3.7.0
with:
args: --enable gofmt --enable gofumpt --timeout 5m --build-tags e2e

- name: Lint
run: make lint-yaml

- name: Run unit tests
run: make unit-test

Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

name: "Code Scanning - Action"

on:
Expand Down Expand Up @@ -49,4 +48,4 @@ jobs:
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
uses: github/codeql-action/analyze@v3
7 changes: 7 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extends: default

rules:
indentation: disable
document-start: disable
comments: disable
line-length: disable
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -581,12 +581,19 @@ $(CLUSTERCTL):

##@ Lint and Verify

GOLANGCI_LINT_EXTRA_ARGS := --enable gofumpt --build-tags e2e
GOLANGCI_LINT_EXTRA_ARGS := --enable gofmt --enable gofumpt --build-tags e2e

.PHONY: lint
lint: $(GOLANGCI_LINT) ## Lint the codebase
$(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_EXTRA_ARGS)

lint-yaml: ## Use yamllint on the yaml file of your projects
ifeq ($(EXPORT_RESULT), true)
GO111MODULE=off go get -u github.com/thomaspoignant/yamllint-checkstyle
$(eval OUTPUT_OPTIONS = | yamllint-checkstyle > yamllint-checkstyle.xml)
endif
docker run --rm -v $(shell pwd):/data cytopia/yamllint -c .yamllint --no-warnings -f parsable $(shell git ls-files '*.yml' '*.yaml') $(OUTPUT_OPTIONS)

.PHONY: lint-fix
lint-fix: $(GOLANGCI_LINT) ## Lint the codebase and run auto-fixers if supported by the linter
GOLANGCI_LINT_EXTRA_ARGS="$(GOLANGCI_LINT_EXTRA_ARGS) --fix" $(MAKE) lint
Expand Down
4 changes: 2 additions & 2 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ stringData:
credentials: |
[
{
"type": "basic_auth",
"data": {
"type": "basic_auth",
"data": {
"prismCentral":{
"username": "${NUTANIX_USER}",
"password": "${NUTANIX_PASSWORD}"
Expand Down
1 change: 0 additions & 1 deletion config/prometheus/monitor.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Prometheus Monitor Service (Metrics)
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
Expand Down
2 changes: 1 addition & 1 deletion config/rbac/nutanixclustertemplate_editor_role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ rules:
- list
- patch
- update
- watch
- watch
6 changes: 3 additions & 3 deletions controllers/nutanixcluster_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestNutanixClusterReconciler(t *testing.T) {

AfterEach(func() {
// Delete ntnxCluster if exists.
k8sClient.Delete(ctx, ntnxCluster)
_ = k8sClient.Delete(ctx, ntnxCluster)
})

Context("Reconcile an NutanixCluster", func() {
Expand Down Expand Up @@ -179,7 +179,7 @@ func TestNutanixClusterReconciler(t *testing.T) {
g.Expect(k8sClient.Create(ctx, ntnxCluster)).To(Succeed())
// Retrieve the applied nutanix cluster objects
appliedNtnxCluster := &infrav1.NutanixCluster{}
k8sClient.Get(ctx, client.ObjectKey{
_ = k8sClient.Get(ctx, client.ObjectKey{
Namespace: ntnxCluster.Namespace,
Name: ntnxCluster.Name,
}, appliedNtnxCluster)
Expand Down Expand Up @@ -213,7 +213,7 @@ func TestNutanixClusterReconciler(t *testing.T) {
g.Expect(k8sClient.Create(ctx, ntnxCluster)).To(Succeed())
// Retrieve the applied nutanix cluster objects
appliedNtnxCluster := &infrav1.NutanixCluster{}
k8sClient.Get(ctx, client.ObjectKey{
_ = k8sClient.Get(ctx, client.ObjectKey{
Namespace: ntnxCluster.Namespace,
Name: ntnxCluster.Name,
}, appliedNtnxCluster)
Expand Down
6 changes: 0 additions & 6 deletions controllers/nutanixmachine_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -827,12 +827,6 @@ func (r *NutanixMachineReconciler) addVMToProject(rctx *nctx.MachineContext, vmM
return nil
}

func (r *NutanixMachineReconciler) isGetRemoteClientConnectionError(err error) bool {
// Check if error contains connection refused message. This can occur during provisioning when Kubernetes API is not available yet.
const expectedErrString = "connect: connection refused"
return strings.Contains(err.Error(), expectedErrString)
}

func (r *NutanixMachineReconciler) GetSubnetAndPEUUIDs(rctx *nctx.MachineContext) (string, []string, error) {
if rctx == nil {
return "", nil, fmt.Errorf("cannot create machine config if machine context is nil")
Expand Down
6 changes: 4 additions & 2 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ const (
capxNamespaceKey = "POD_NAMESPACE"
)

var ErrPrismAddressNotSet = fmt.Errorf("cannot get credentials if Prism Address is not set")
var ErrPrismPortNotSet = fmt.Errorf("cannot get credentials if Prism Port is not set")
var (
ErrPrismAddressNotSet = fmt.Errorf("cannot get credentials if Prism Address is not set")
ErrPrismPortNotSet = fmt.Errorf("cannot get credentials if Prism Port is not set")
)

type NutanixClientHelper struct {
secretInformer coreinformers.SecretInformer
Expand Down
3 changes: 2 additions & 1 deletion pkg/client/client_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package client

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestClient(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/context/context_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package context

import (
"testing"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
capiv1 "sigs.k8s.io/cluster-api/api/v1beta1"
"testing"

infrav1 "github.com/nutanix-cloud-native/cluster-api-provider-nutanix/api/v1beta1"
)
Expand Down
4 changes: 2 additions & 2 deletions templates/base-root/nutanix-ccm-secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ stringData:
credentials: |
[
{
"type": "basic_auth",
"data": {
"type": "basic_auth",
"data": {
"prismCentral":{
"username": "${NUTANIX_USER}",
"password": "${NUTANIX_PASSWORD}"
Expand Down
6 changes: 3 additions & 3 deletions templates/base-root/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ stringData:
credentials: |
[
{
"type": "basic_auth",
"data": {
"type": "basic_auth",
"data": {
"prismCentral":{
"username": "${NUTANIX_USER}",
"username": "${NUTANIX_USER}",
"password": "${NUTANIX_PASSWORD}"
}
}
Expand Down
2 changes: 1 addition & 1 deletion templates/base/ccm-patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ spec:
joinConfiguration:
nodeRegistration:
kubeletExtraArgs:
cloud-provider: external
cloud-provider: external
2 changes: 1 addition & 1 deletion templates/base/cluster-without-topology.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ spec:
infrastructureRef:
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
kind: NutanixCluster
name: "${CLUSTER_NAME}"
name: "${CLUSTER_NAME}"
2 changes: 1 addition & 1 deletion templates/base/kcp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,4 @@ spec:
- echo export KUBECONFIG=/etc/kubernetes/admin.conf >> /root/.bashrc
- echo "after kubeadm call" > /var/log/postkubeadm.log
useExperimentalRetryJoin: true
verbosity: 10
verbosity: 10
2 changes: 1 addition & 1 deletion templates/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ bases:
- ./mhc.yaml

patchesStrategicMerge:
- ./ccm-patch.yaml
- ./ccm-patch.yaml
2 changes: 1 addition & 1 deletion templates/base/nutanix-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ spec:
kind: ConfigMap
controlPlaneEndpoint:
host: "${CONTROL_PLANE_ENDPOINT_IP}"
port: ${CONTROL_PLANE_ENDPOINT_PORT=6443}
port: ${CONTROL_PLANE_ENDPOINT_PORT=6443}
2 changes: 1 addition & 1 deletion templates/clusterclass/clusterclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -301,4 +301,4 @@ spec:
type: string
subnetName:
type: string
type: object
type: object
2 changes: 1 addition & 1 deletion templates/clusterclass/kcpt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@ spec:
- echo "before kubeadm call" > /var/log/prekubeadm.log
- hostnamectl set-hostname "{{ ds.meta_data.hostname }}"
useExperimentalRetryJoin: true
verbosity: 10
verbosity: 10
2 changes: 1 addition & 1 deletion templates/clusterclass/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ bases:
- ./nmt-cp.yaml
- ./nmt-md.yaml
- ./kcpt.yaml
- ./kct.yaml
- ./kct.yaml
4 changes: 2 additions & 2 deletions templates/clusterclass/nct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ kind: NutanixClusterTemplate
metadata:
name: ${CLUSTER_CLASS_NAME}-nct
spec:
template:
template:
spec:
failureDomains: []
failureDomains: []
2 changes: 1 addition & 1 deletion templates/clusterclass/nmt-cp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ spec:
# name: "NUTANIX_PROJECT_NAME"
# gpus:
# - type: name
# name: "GPU NAME"
# name: "GPU NAME"
2 changes: 1 addition & 1 deletion templates/clusterclass/nmt-md.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ spec:
# name: "NUTANIX_PROJECT_NAME"
# gpus:
# - type: name
# name: "GPU NAME"
# name: "GPU NAME"
2 changes: 1 addition & 1 deletion templates/csi/csi-patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ metadata:
labels:
csi: "nutanix"
name: "${CLUSTER_NAME}"
namespace: "${NAMESPACE}"
namespace: "${NAMESPACE}"
2 changes: 1 addition & 1 deletion templates/csi/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ resources:
- nutanix-csi-crs.yaml

patchesStrategicMerge:
- csi-patch.yaml
- csi-patch.yaml
1 change: 0 additions & 1 deletion templates/csi/nutanix-csi-crs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ spec:
- kind: ConfigMap
name: nutanix-csi
strategy: ApplyOnce

12 changes: 6 additions & 6 deletions templates/csi/nutanix-csi-snapshot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ apiVersion: v1
kind: ServiceAccount
metadata:
name: csi-snapshot-webhook
namespace: ntnx-system
namespace: ntnx-system
---
# Source: nutanix-csi-snapshot/templates/volumesnapshotclasses_rel60.yaml
apiVersion: apiextensions.k8s.io/v1
Expand Down Expand Up @@ -928,7 +928,7 @@ metadata:
subjects:
- kind: ServiceAccount
name: csi-snapshot-webhook
namespace: ntnx-system
namespace: ntnx-system
roleRef:
kind: ClusterRole
name: csi-snapshot-webhook-runner
Expand Down Expand Up @@ -1113,11 +1113,11 @@ metadata:
webhooks:
- name: "validation-webhook.snapshot.storage.k8s.io"
rules:
- apiGroups: ["snapshot.storage.k8s.io"]
- apiGroups: ["snapshot.storage.k8s.io"]
apiVersions: ["v1", "v1beta1"]
operations: ["CREATE", "UPDATE"]
resources: ["volumesnapshots", "volumesnapshotcontents"]
scope: "*"
operations: ["CREATE", "UPDATE"]
resources: ["volumesnapshots", "volumesnapshotcontents"]
scope: "*"
clientConfig:
service:
namespace: ntnx-system
Expand Down
4 changes: 2 additions & 2 deletions templates/csi/nutanix-csi-storage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ roleRef:
---
# Source: nutanix-csi-storage/templates/service-prometheus-csi.yaml
# Copyright 2021 Nutanix Inc
#
#
# example usage: kubectl create -f <this_file>
#

Expand Down Expand Up @@ -203,7 +203,7 @@ spec:
allowPrivilegeEscalation: true
image: quay.io/karbon/ntnx-csi:v2.5.1
imagePullPolicy: IfNotPresent
args :
args:
- "--endpoint=$(CSI_ENDPOINT)"
- "--nodeid=$(NODE_ID)"
- "--drivername=csi.nutanix.com"
Expand Down
2 changes: 1 addition & 1 deletion templates/topology/ccm-patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ kind: Cluster
metadata:
labels:
ccm: "nutanix"
name: "${CLUSTER_NAME}"
name: "${CLUSTER_NAME}"
2 changes: 1 addition & 1 deletion templates/topology/cluster-with-topology.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ spec:
systemDiskSize: "${NUTANIX_SYSTEMDISK_SIZE=40Gi}"
imageName: "${NUTANIX_MACHINE_TEMPLATE_IMAGE_NAME}"
clusterName: "${NUTANIX_PRISM_ELEMENT_CLUSTER_NAME}"
subnetName: "${NUTANIX_SUBNET_NAME}"
subnetName: "${NUTANIX_SUBNET_NAME}"
2 changes: 1 addition & 1 deletion templates/topology/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ bases:
- ./cluster-with-topology.yaml

patchesStrategicMerge:
- ./ccm-patch.yaml
- ./ccm-patch.yaml
Loading

0 comments on commit c075eb4

Please sign in to comment.