From 77d0591482677a70329f931d0f29c21d3d087930 Mon Sep 17 00:00:00 2001 From: kavyashree-r Date: Wed, 20 Nov 2024 12:28:52 +0530 Subject: [PATCH] code coverage for storagequota --- cmd/vsphere-csi/main.go | 13 +++++++++++-- cmd/vsphere-csi/main_test.go | 9 +++++++++ hack/release.sh | 2 ++ images/driver/Dockerfile | 23 +++++++++++++++++++---- images/syncer/Dockerfile | 6 +++--- pkg/syncer/metadatasyncer.go | 10 +++++----- 6 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 cmd/vsphere-csi/main_test.go diff --git a/cmd/vsphere-csi/main.go b/cmd/vsphere-csi/main.go index 29b3a4958c..dc30f4c922 100644 --- a/cmd/vsphere-csi/main.go +++ b/cmd/vsphere-csi/main.go @@ -23,6 +23,7 @@ import ( "os" "os/signal" "syscall" + "time" csiconfig "sigs.k8s.io/vsphere-csi-driver/v3/pkg/common/config" "sigs.k8s.io/vsphere-csi-driver/v3/pkg/common/utils" @@ -92,8 +93,16 @@ func main() { } }() - vSphereCSIDriver := service.NewDriver() - vSphereCSIDriver.Run(ctx, CSIEndpoint) + //vSphereCSIDriver := service.NewDriver() + //vSphereCSIDriver.Run(ctx, CSIEndpoint) + go func() { + vSphereCSIDriver := service.NewDriver() + vSphereCSIDriver.Run(ctx, CSIEndpoint) + }() + + // Sleep for 60 min in parallel + sleepDuration := 15 * time.Minute + time.Sleep(sleepDuration) } diff --git a/cmd/vsphere-csi/main_test.go b/cmd/vsphere-csi/main_test.go new file mode 100644 index 0000000000..d36b8c107b --- /dev/null +++ b/cmd/vsphere-csi/main_test.go @@ -0,0 +1,9 @@ +package main + +import ( + "testing" +) + +func TestRunMain(t *testing.T) { + main() +} diff --git a/hack/release.sh b/hack/release.sh index 3612228aaa..63ac2e613c 100755 --- a/hack/release.sh +++ b/hack/release.sh @@ -150,6 +150,8 @@ function build_syncer_image_linux() { --build-arg "GOPROXY=${GOPROXY}" \ --build-arg "GIT_COMMIT=${GIT_COMMIT}" \ --build-arg "GOLANG_IMAGE=${GOLANG_IMAGE}" \ + --build-arg ARCH=amd64 \ + --platform "linux/$ARCH" \ . if [ "${LATEST}" ]; then diff --git a/images/driver/Dockerfile b/images/driver/Dockerfile index 7501d668fc..a5d114a444 100644 --- a/images/driver/Dockerfile +++ b/images/driver/Dockerfile @@ -40,8 +40,8 @@ COPY pkg/ pkg/ COPY cmd/ cmd/ ENV CGO_ENABLED=0 ENV GOPROXY ${GOPROXY:-https://proxy.golang.org} -RUN go build -a -ldflags="-w -s -extldflags=static -X sigs.k8s.io/vsphere-csi-driver/v3/pkg/csi/service.Version=${VERSION}" -o vsphere-csi ./cmd/vsphere-csi - +#RUN go build -a -ldflags="-w -s -extldflags=static -X sigs.k8s.io/vsphere-csi-driver/v3/pkg/csi/service.Version=${VERSION}" -o vsphere-csi ./cmd/vsphere-csi +RUN go test -v -c -coverpkg=./... ./cmd/vsphere-csi/ -o /build/vsphere-csi.test ################################################################################ ## MAIN STAGE ## ################################################################################ @@ -72,6 +72,21 @@ RUN tdnf -y install \ # Remove cached data RUN tdnf clean all -COPY --from=builder /build/vsphere-csi /bin/vsphere-csi +#COPY --from=builder /build/vsphere-csi /bin/vsphere-csi + +#ENTRYPOINT ["/bin/vsphere-csi"] +RUN mkdir -p /tmp/cloud + +RUN chmod 777 /tmp/cloud + +# Save the timestamp in an environment variable +ENV TIMESTAMP $(date +%s) + +# Create an empty file with the desired name +RUN touch /tmp/cloud/contr-dump-$TIMESTAMP.out + +COPY --from=builder /build/vsphere-csi.test /bin/vsphere-csi.test + +#ENTRYPOINT ["/bin/vsphere-csi.test", "-test.coverprofile=/tmp/cloud/contr-dump.out"] +ENTRYPOINT ["/bin/sh", "-c", "/bin/vsphere-csi.test -test.coverprofile=/tmp/cloud/contr-$(date +%s).out"] -ENTRYPOINT ["/bin/vsphere-csi"] diff --git a/images/syncer/Dockerfile b/images/syncer/Dockerfile index 4e400d11a5..f58a645b58 100644 --- a/images/syncer/Dockerfile +++ b/images/syncer/Dockerfile @@ -41,8 +41,8 @@ ENV CGO_ENABLED=0 ENV GOPROXY ${GOPROXY:-https://proxy.golang.org} -RUN go build -a -ldflags="-w -s -extldflags=static -X sigs.k8s.io/vsphere-csi-driver/v3/pkg/syncer.Version=${VERSION}" -o vsphere-syncer ./cmd/syncer - +##RUN go build -a -ldflags="-w -s -extldflags=static -X sigs.k8s.io/vsphere-csi-driver/v3/pkg/syncer.Version=${VERSION}" -o vsphere-syncer ./cmd/syncer +RUN go test -v -c -coverpkg=./... ./cmd/syncer/ -o /build/vsphere-syncer.test ################################################################################ ## MAIN STAGE ## ################################################################################ @@ -56,7 +56,7 @@ LABEL git_commit=$GIT_COMMIT RUN tdnf -y upgrade -COPY --from=builder /build/vsphere-syncer /bin/vsphere-syncer +##COPY --from=builder /build/vsphere-syncer /bin/vsphere-syncer # Remove cached data RUN tdnf clean all diff --git a/pkg/syncer/metadatasyncer.go b/pkg/syncer/metadatasyncer.go index f718976e59..5d3c051336 100644 --- a/pkg/syncer/metadatasyncer.go +++ b/pkg/syncer/metadatasyncer.go @@ -733,10 +733,10 @@ func InitMetadataSyncer(ctx context.Context, clusterFlavor cnstypes.CnsClusterFl metadataSyncer.pvLister = metadataSyncer.k8sInformerManager.GetPVLister() metadataSyncer.pvcLister = metadataSyncer.k8sInformerManager.GetPVCLister() metadataSyncer.podLister = metadataSyncer.k8sInformerManager.GetPodLister() - stopCh := metadataSyncer.k8sInformerManager.Listen() - if stopCh == nil { - return logger.LogNewError(log, "Failed to sync informer caches") - } + // stopCh := metadataSyncer.k8sInformerManager.Listen() + // if stopCh == nil { + // return logger.LogNewError(log, "Failed to sync informer caches") + // } log.Infof("Initialized metadata syncer") fullSyncTicker := time.NewTicker(time.Duration(getFullSyncIntervalInMin(ctx)) * time.Minute) @@ -982,7 +982,7 @@ func InitMetadataSyncer(ctx context.Context, clusterFlavor cnstypes.CnsClusterFl }() } - <-stopCh + //<-stopCh return nil }