diff --git a/Makefile b/Makefile index 53c9f94..eaf8114 100644 --- a/Makefile +++ b/Makefile @@ -7,8 +7,8 @@ help: @echo @echo "build - Builds the code locally" @echo "clean - Cleans the local build" - @echo "docker - Builds Docker images" - @echo "push - Pushes Docker images to a registry" + @echo "podman - Builds Podman images" + @echo "push - Pushes Podman images to a registry" @echo "check - Runs code checking tools: lint, format, gosec, and vet" @echo "test - Runs the unit tests" @echo @@ -37,17 +37,18 @@ build-base-image: download-csm-common @echo "Base image build: SUCCESS" $(eval BASEIMAGE=mpst-ubimicro:latest) -.PHONY: docker -docker: build-base-image - docker build -t csm-metrics-powerstore -f Dockerfile --build-arg BASEIMAGE=$(BASEIMAGE) --build-arg GOIMAGE=$(DEFAULT_GOIMAGE) . +# Pre-requisites: RHEL, buildah, podman +.PHONY: podman +podman: build-base-image + podman build -t csm-metrics-powerstore -f Dockerfile --build-arg BASEIMAGE=$(BASEIMAGE) --build-arg GOIMAGE=$(DEFAULT_GOIMAGE) . .PHONY: push push: - docker push ${DOCKER_REPO}/csm-metrics-powerstore\:latest + podman push ${DOCKER_REPO}/csm-metrics-powerstore\:latest .PHONY: tag tag: - docker tag csm-metrics-powerstore\:latest ${DOCKER_REPO}/csm-metrics-powerstore\:latest + podman tag csm-metrics-powerstore\:latest ${DOCKER_REPO}/csm-metrics-powerstore\:latest .PHONY: check check: diff --git a/internal/common/common.go b/internal/common/common.go index 00e6e99..be8b0cd 100644 --- a/internal/common/common.go +++ b/internal/common/common.go @@ -90,7 +90,7 @@ func GetPowerStoreArrays(filePath string, logger *logrus.Logger) (map[string]*se if err != nil { logger.Errorf("can't get throttling rate limit, using default") } else { - clientOptions.SetRateLimit(uint64(rateLimit)) + clientOptions.SetRateLimit(uint64(rateLimit)) // #nosec G115 -- This is a false positive } } diff --git a/internal/service/service.go b/internal/service/service.go index b80dafe..e2553a4 100644 --- a/internal/service/service.go +++ b/internal/service/service.go @@ -31,8 +31,6 @@ import ( "github.com/sirupsen/logrus" ) -var _ Service = (*PowerStoreService)(nil) - const ( // DefaultMaxPowerStoreConnections is the number of workers that can query powerstore at a time DefaultMaxPowerStoreConnections = 10 @@ -42,6 +40,35 @@ const ( nfsProtocol = "nfs" ) +var _ Service = (*PowerStoreService)(nil) + +func (s *PowerStoreService) getPowerStoreClient(_ context.Context, arrayIP string) (PowerStoreClient, error) { + if goPowerStoreClient, ok := s.PowerStoreClients[arrayIP]; ok { + return goPowerStoreClient, nil + } + return nil, fmt.Errorf("unable to find client") +} + +func toMegabytes(bytes float32) float32 { + return bytes / 1024 / 1024 +} + +func toMegabytesInt64(bytes int64) int64 { + return bytes / 1024 / 1024 +} + +func toMilliseconds(microseconds float32) float32 { + return microseconds / 1000 +} + +// timeSince will log the amount of time spent in a given function +func (s *PowerStoreService) timeSince(start time.Time, fName string) { + s.Logger.WithFields(logrus.Fields{ + "duration": fmt.Sprintf("%v", time.Since(start)), + "function": fName, + }).Info("function duration") +} + // Service contains operations that would be used to interact with a PowerStore system // //go:generate mockgen -destination=mocks/service_mocks.go -package=mocks github.com/dell/csm-metrics-powerstore/internal/service Service @@ -301,33 +328,6 @@ func (s *PowerStoreService) pushVolumeMetrics(ctx context.Context, volumeMetrics return ch } -func (s *PowerStoreService) getPowerStoreClient(_ context.Context, arrayIP string) (PowerStoreClient, error) { - if goPowerStoreClient, ok := s.PowerStoreClients[arrayIP]; ok { - return goPowerStoreClient, nil - } - return nil, fmt.Errorf("unable to find client") -} - -func toMegabytes(bytes float32) float32 { - return bytes / 1024 / 1024 -} - -func toMegabytesInt64(bytes int64) int64 { - return bytes / 1024 / 1024 -} - -func toMilliseconds(microseconds float32) float32 { - return microseconds / 1000 -} - -// timeSince will log the amount of time spent in a given function -func (s *PowerStoreService) timeSince(start time.Time, fName string) { - s.Logger.WithFields(logrus.Fields{ - "duration": fmt.Sprintf("%v", time.Since(start)), - "function": fName, - }).Info("function duration") -} - // gatherSpaceVolumeMetrics will return a channel of space volume metrics based on the input of volumes func (s *PowerStoreService) gatherSpaceVolumeMetrics(ctx context.Context, volumes <-chan k8s.VolumeInfo) <-chan *VolumeSpaceMetricsRecord { start := time.Now()