From 07b28b31e1a494a7f42a4374f93402d2937ce422 Mon Sep 17 00:00:00 2001 From: Rahul krishnan R A Date: Thu, 4 Mar 2021 07:18:03 +0000 Subject: [PATCH] fix for the issues reported by the Go Report Card Signed-off-by: Rahul krishnan R A --- .../api/apps/v1/deployment/deployment.go | 2 +- .../api/apps/v1/deployment/kubernetes.go | 1 + .../api/core/v1/container/container_test.go | 6 ++--- .../v1/podtemplatespec/podtemplatespec.go | 1 + .../podtemplatespec/podtemplatespec_test.go | 4 ++-- provisioner/helper_kernel_nfs_server.go | 22 +++++++++---------- tests/sanity_test.go | 4 ++-- 7 files changed, 21 insertions(+), 19 deletions(-) diff --git a/pkg/kubernetes/api/apps/v1/deployment/deployment.go b/pkg/kubernetes/api/apps/v1/deployment/deployment.go index f40078f..d46b094 100644 --- a/pkg/kubernetes/api/apps/v1/deployment/deployment.go +++ b/pkg/kubernetes/api/apps/v1/deployment/deployment.go @@ -171,7 +171,7 @@ func (b *Builder) WithNodeSelector(selector map[string]string) *Builder { return b } -// WithNodeSelector Sets the node selector with the provided argument. +// WithNodeSelectorNew Sets the node selector with the provided argument. func (b *Builder) WithNodeSelectorNew(selector map[string]string) *Builder { if len(selector) == 0 { b.errors = append( diff --git a/pkg/kubernetes/api/apps/v1/deployment/kubernetes.go b/pkg/kubernetes/api/apps/v1/deployment/kubernetes.go index 3f0767e..dcd27ff 100644 --- a/pkg/kubernetes/api/apps/v1/deployment/kubernetes.go +++ b/pkg/kubernetes/api/apps/v1/deployment/kubernetes.go @@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ + package deployment import ( diff --git a/pkg/kubernetes/api/core/v1/container/container_test.go b/pkg/kubernetes/api/core/v1/container/container_test.go index 9da78b9..4e0f53e 100644 --- a/pkg/kubernetes/api/core/v1/container/container_test.go +++ b/pkg/kubernetes/api/core/v1/container/container_test.go @@ -287,7 +287,7 @@ func TestBuilderWithEnvsNew(t *testing.T) { }{ "Test Builder with envList": { envList: []corev1.EnvVar{ - corev1.EnvVar{}, + {}, }, builder: &Builder{con: &container{ corev1.Container{}, @@ -324,7 +324,7 @@ func TestBuilderWithPortsNew(t *testing.T) { }{ "Test Builder with portList": { portList: []corev1.ContainerPort{ - corev1.ContainerPort{}, + {}, }, builder: &Builder{con: &container{ corev1.Container{}, @@ -396,7 +396,7 @@ func TestBuilderWithVolumeMountsNew(t *testing.T) { }{ "Test Builder with volume mounts": { mounts: []corev1.VolumeMount{ - corev1.VolumeMount{}, + {}, }, builder: &Builder{con: &container{ corev1.Container{}, diff --git a/pkg/kubernetes/api/core/v1/podtemplatespec/podtemplatespec.go b/pkg/kubernetes/api/core/v1/podtemplatespec/podtemplatespec.go index 9eea9a5..490221f 100644 --- a/pkg/kubernetes/api/core/v1/podtemplatespec/podtemplatespec.go +++ b/pkg/kubernetes/api/core/v1/podtemplatespec/podtemplatespec.go @@ -214,6 +214,7 @@ func (b *Builder) WithNodeSelectorNew(nodeselectors map[string]string) *Builder return b } +//WithNodeSelectorByValue overrides the NodeSelector with new values func (b *Builder) WithNodeSelectorByValue(nodeselectors map[string]string) *Builder { // copy of original map newnodeselectors := map[string]string{} diff --git a/pkg/kubernetes/api/core/v1/podtemplatespec/podtemplatespec_test.go b/pkg/kubernetes/api/core/v1/podtemplatespec/podtemplatespec_test.go index 4f4b676..021223c 100644 --- a/pkg/kubernetes/api/core/v1/podtemplatespec/podtemplatespec_test.go +++ b/pkg/kubernetes/api/core/v1/podtemplatespec/podtemplatespec_test.go @@ -354,7 +354,7 @@ func TestBuilderWithTolerations(t *testing.T) { }{ "Test Builder with tolerations": { tolerations: []corev1.Toleration{ - corev1.Toleration{}, + {}, }, builder: &Builder{podtemplatespec: &PodTemplateSpec{ Object: &corev1.PodTemplateSpec{}, @@ -391,7 +391,7 @@ func TestBuilderWithTolerationsNew(t *testing.T) { }{ "Test Builder with tolerations": { tolerations: []corev1.Toleration{ - corev1.Toleration{}, + {}, }, builder: &Builder{podtemplatespec: &PodTemplateSpec{ Object: &corev1.PodTemplateSpec{}, diff --git a/provisioner/helper_kernel_nfs_server.go b/provisioner/helper_kernel_nfs_server.go index 0f4d18c..7523976 100644 --- a/provisioner/helper_kernel_nfs_server.go +++ b/provisioner/helper_kernel_nfs_server.go @@ -37,10 +37,10 @@ const ( // NFSPVFinalizer represents finalizer string used by NFSPV NFSPVFinalizer = "nfs.openebs.io/finalizer" - //NFS Server Port + //NFSServerPort set the NFS Server Port NFSServerPort = 2049 - //RPC Bind Port + //RPCBindPort set the RPC Bind Port RPCBindPort = 111 ) @@ -80,7 +80,7 @@ func (p *Provisioner) createBackendPVC(nfsServerOpts *KernelNFSServerOptions) er klog.V(4).Infof("Verifying if PVC(%v) for NFS storage was already created.", pvcName) //Check if the PVC is already created. This can happen - //if the previous reconcilation of PVC-PV, resulted in + //if the previous reconciliation of PVC-PV, resulted in //creating a PVC, but was not yet available for 60+ seconds _, err := persistentvolumeclaim.NewKubeClient(). WithNamespace(p.namespace). @@ -172,7 +172,7 @@ func (p *Provisioner) createDeployment(nfsServerOpts *KernelNFSServerOptions) er klog.V(4).Infof("Verifying if Deployment(%v) for NFS storage was already created.", deployName) //Check if the Deployment is already created. This can happen - //if the previous reconcilation of PVC-PV, resulted in + //if the previous reconciliation of PVC-PV, resulted in //creating a Deployment, but was not yet available for 60+ seconds _, err := deployment.NewKubeClient(). WithNamespace(p.namespace). @@ -207,7 +207,7 @@ func (p *Provisioner) createDeployment(nfsServerOpts *KernelNFSServerOptions) er WithImage("itsthenetwork/nfs-server-alpine"). WithEnvsNew( []corev1.EnvVar{ - corev1.EnvVar{ + { Name: "SHARED_DIRECTORY", Value: "/nfsshare", }, @@ -215,11 +215,11 @@ func (p *Provisioner) createDeployment(nfsServerOpts *KernelNFSServerOptions) er ). WithPortsNew( []corev1.ContainerPort{ - corev1.ContainerPort{ + { Name: "nfs", ContainerPort: NFSServerPort, }, - corev1.ContainerPort{ + { Name: "rpcbind", ContainerPort: RPCBindPort, }, @@ -228,7 +228,7 @@ func (p *Provisioner) createDeployment(nfsServerOpts *KernelNFSServerOptions) er WithPrivilegedSecurityContext(&secContext). WithVolumeMountsNew( []corev1.VolumeMount{ - corev1.VolumeMount{ + { Name: "exports-dir", MountPath: "/nfsshare", }, @@ -313,7 +313,7 @@ func (p *Provisioner) createService(nfsServerOpts *KernelNFSServerOptions) error klog.V(4).Infof("Verifying if Service(%v) for NFS storage was already created.", svcName) //Check if the Service is already created. This can happen - //if the previous reconcilation of PVC-PV, resulted in + //if the previous reconciliation of PVC-PV, resulted in //creating a Service, but was not yet available for 60+ seconds _, err := service.NewKubeClient(). WithNamespace(p.namespace). @@ -336,11 +336,11 @@ func (p *Provisioner) createService(nfsServerOpts *KernelNFSServerOptions) error WithName(svcName). WithPorts( []corev1.ServicePort{ - corev1.ServicePort{ + { Name: "nfs", Port: NFSServerPort, }, - corev1.ServicePort{ + { Name: "rpcbind", Port: RPCBindPort, }, diff --git a/tests/sanity_test.go b/tests/sanity_test.go index a0abb97..addf549 100644 --- a/tests/sanity_test.go +++ b/tests/sanity_test.go @@ -98,7 +98,7 @@ var _ = Describe("TEST NFS PV", func() { ). WithVolumeMountsNew( []corev1.VolumeMount{ - corev1.VolumeMount{ + { Name: "demo-vol1", MountPath: "/mnt/store1", }, @@ -114,7 +114,7 @@ var _ = Describe("TEST NFS PV", func() { Build() Expect(err).ShouldNot( HaveOccurred(), - "while building delpoyment {%s} in namespace {%s}", + "while building deployment {%s} in namespace {%s}", deployName, namespaceObj.Name, )