Skip to content

Commit

Permalink
replace docker build with podman build and fix gosec issue (#82)
Browse files Browse the repository at this point in the history
  • Loading branch information
chimanjain authored Sep 19, 2024
1 parent 38df56e commit 9357c68
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 37 deletions.
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion internal/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
58 changes: 29 additions & 29 deletions internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 9357c68

Please sign in to comment.