Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore all files which are not go type or shell scripts
!**/*.go
!**/*.mod
!**/*.sum
!**/*.sh
13 changes: 4 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM golang:1.22 AS builder
FROM golang:1.23 AS builder

WORKDIR /workspace

# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum

# Copy the Go source tree
COPY cmd/ cmd/
COPY internal/ internal/
COPY pkg/ pkg/
# Copy all source files, avoid producing multiple layers
# See .dockerignore for exclusions
COPY . .

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o nnf-ec ./cmd/nnf_ec.go
Expand Down
79 changes: 61 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,62 +21,105 @@ PROD_VERSION=$(shell sed 1q .version)
DEV_IMGNAME=nnf-ec
DTR_IMGPATH=ghcr.io/nearnodeflash/$(DEV_IMGNAME)

all: image

vendor:
.DEFAULT_GOAL := help

## Display this help message
help:
@echo "NNF Element Controller (nnf-ec) Makefile"
@echo ""
@echo "Available targets:"
@echo ""
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
@echo ""
@echo "Docker cleanup targets:"
@echo " clean-images Remove all project-related Docker images"
@echo " clean-docker-all Remove ALL unused Docker resources (aggressive)"
@echo " clean-docker-images Remove unused Docker images only"
@echo " clean-docker-cache Remove Docker build cache"
@echo " clean-project-docker Remove project Docker images and unused resources"
@echo ""

all: image ## Build the default Docker image

vendor: ## Download Go module dependencies
go mod vendor

vet:
vet: ## Run Go vet on all packages
go vet `go list -f {{.Dir}} ./...`

fmt:
fmt: ## Format Go source code
go fmt `go list -f {{.Dir}} ./...`

generate:
generate: ## Generate code and redfish/swordfish message registries
( cd ./pkg/manager-message-registry/generator && go build msgenerator.go )
go generate ./...
go fmt ./pkg/manager-message-registry/registries

test:
test: ## Run Go unit tests locally
go test -v ./...

linux:
linux: ## Build Linux binary
env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ${DEV_IMGNAME} ./cmd/nnf_ec.go

image:
image: ## Build Docker image
docker build --file Dockerfile --label $(DTR_IMGPATH):$(PROD_VERSION) --tag $(DTR_IMGPATH):$(PROD_VERSION) .

container-unit-test:
container-unit-test: ## Run containerized unit tests
docker build -f Dockerfile --label $(DTR_IMGPATH)-$@:$(PROD_VERSION)-$@ -t $(DTR_IMGPATH)-$@:$(PROD_VERSION) --target $@ .
docker run --rm -t --name $@ -v $(PWD):$(PWD):rw,z $(DTR_IMGPATH)-$@:$(PROD_VERSION)

# This and the corresponding clean-lint should go away and move to git pre-commit hook
lint:
lint: ## Run linting checks in Docker container
docker build -f Dockerfile --label $(DTR_IMGPATH)-$@:$(PROD_VERSION)-$@ -t $(DTR_IMGPATH)-$@:$(PROD_VERSION) --target $@ .
docker run --rm -t --name $@ -v $(PWD):$(PWD):rw,z $(DTR_IMGPATH)-$@:$(PROD_VERSION)

# This and the cooresponding clean-codestyle should go away and move to git pre-commit hook
codestyle:
codestyle: ## Run code style checks in Docker container
docker build -f Dockerfile --label $(DTR_IMGPATH)-$@:$(PROD_VERSION) -t $(DTR_IMGPATH)-$@:$(PROD_VERSION) --target $@ .
docker run --rm -t --name $@ -v $(PWD):$(PWD):rw,z $(DTR_IMGPATH)-$@:$(PROD_VERSION)

clean-lint:
clean-lint: ## Clean lint Docker images and containers
docker rmi $(DTR_IMGPATH)-lint:$(PROD_VERSION) || true
docker container rm lint || true

clean-codestyle:
clean-codestyle: ## Clean codestyle Docker images and containers
docker rmi $(DTR_IMGPATH)-codestyle:$(PROD_VERSION) || true
docker container rm codestyle || true

clean-container-unit-test: ## Clean container-unit-test Docker images and containers
docker rmi $(DTR_IMGPATH)-container-unit-test:$(PROD_VERSION) || true
docker container rm container-unit-test || true

# push:
# docker push $(DTR_IMGPATH):$(PROD_VERSION)

kind-push: image
kind-push: image ## Load Docker image into kind cluster
kind load docker-image $(DTR_IMGPATH):$(PROD_VERSION)

clean: clean-db
clean: clean-db ## Clean build artifacts and Docker resources
docker container prune --force
docker image prune --force
docker rmi $(DTR_IMGPATH):$(PROD_VERSION)
docker rmi $(DTR_IMGPATH):$(PROD_VERSION) || true
go clean all

clean-db:
clean-images: ## Clean all Docker images related to this project
docker rmi $(DTR_IMGPATH):$(PROD_VERSION) || true
docker rmi $(DTR_IMGPATH)-container-unit-test:$(PROD_VERSION) || true
docker rmi $(DTR_IMGPATH)-lint:$(PROD_VERSION) || true
docker rmi $(DTR_IMGPATH)-codestyle:$(PROD_VERSION) || true

clean-docker-all: ## Remove ALL unused Docker resources (aggressive)
docker system prune -a --volumes --force

clean-docker-images: ## Remove unused Docker images only
docker image prune --force

clean-docker-cache: ## Remove Docker build cache
docker builder prune --force

clean-project-docker: clean-images ## Remove project Docker images and unused resources
docker container prune --force
docker image prune --force

clean-db: ## Remove all database files
find . -name "*.db" -type d -exec rm -rf {} +
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/NearNodeFlash/nnf-ec

go 1.22.0

toolchain go1.22.5
go 1.23.9

require (
github.com/HewlettPackard/structex v1.0.4
Expand Down
5 changes: 0 additions & 5 deletions kubernetes/nnf-ec/Chart.yaml

This file was deleted.

Binary file removed kubernetes/nnf-ec/charts/cray-service-2.0.0.tgz
Binary file not shown.
Empty file.
45 changes: 0 additions & 45 deletions kubernetes/nnf-ec/templates/_helpers.tpl

This file was deleted.

32 changes: 0 additions & 32 deletions kubernetes/nnf-ec/templates/role.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions kubernetes/nnf-ec/templates/role_binding.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions kubernetes/nnf-ec/templates/service_account.yaml

This file was deleted.

53 changes: 0 additions & 53 deletions kubernetes/nnf-ec/values.yaml

This file was deleted.

16 changes: 9 additions & 7 deletions pkg/manager-nnf/allocation_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,18 @@ func (p *SpareAllocationPolicy) CheckAndAdjustCapacity() error {

if p.compliance != RelaxedAllocationComplianceType {

if len(p.storage) < SpareAllocationPolicyMinimumDriveCount {
return fmt.Errorf("Insufficient drive count. Required: %d Available: %d", SpareAllocationPolicyMinimumDriveCount, len(p.storage))
driveCount := uint64(len(p.storage))
if driveCount < SpareAllocationPolicyMinimumDriveCount {
return fmt.Errorf("Insufficient drive count. Required: %d Available: %d", SpareAllocationPolicyMinimumDriveCount, driveCount)
}

roundUpToMultiple := func(n, m uint64) uint64 { // Round 'n' up to a multiple of 'm'
return ((n + m - 1) / m) * m
}

// Validate each drive can contribute sufficient capacity towards the entire pool.
poolCapacityBytes := roundUpToMultiple(p.capacityBytes, SpareAllocationPolicyMinimumDriveCount)
driveCapacityBytes := roundUpToMultiple(poolCapacityBytes/SpareAllocationPolicyMinimumDriveCount, 4096)
poolCapacityBytes := roundUpToMultiple(p.capacityBytes, driveCount)
driveCapacityBytes := roundUpToMultiple(poolCapacityBytes/driveCount, 4096)

for _, s := range p.storage {
if driveCapacityBytes > s.UnallocatedBytes() {
Expand All @@ -180,7 +181,7 @@ func (p *SpareAllocationPolicy) CheckAndAdjustCapacity() error {
}

// Adjust the pool's capacity such that it is a multiple of the number drives.
p.capacityBytes = driveCapacityBytes * uint64(len(p.storage))
p.capacityBytes = driveCapacityBytes * driveCount
}

if availableBytes < p.capacityBytes {
Expand All @@ -193,7 +194,8 @@ func (p *SpareAllocationPolicy) CheckAndAdjustCapacity() error {
// Allocate - allocate the storage
func (p *SpareAllocationPolicy) Allocate() ([]nvme.ProvidingVolume, error) {

perStorageCapacityBytes := p.capacityBytes / uint64(len(p.storage))
driveCount := uint64(len(p.storage))
perStorageCapacityBytes := p.capacityBytes / driveCount
remainingCapacityBytes := p.capacityBytes

volumes := []nvme.ProvidingVolume{}
Expand All @@ -204,7 +206,7 @@ func (p *SpareAllocationPolicy) Allocate() ([]nvme.ProvidingVolume, error) {
// Leftover bytes are placed on trailing volume; note that this
// is never the case for strict allocation in which the requested
// allocation must be a multiple of the storage size.
if idx == len(p.storage)-1 {
if idx == int(driveCount-1) {
capacityBytes = remainingCapacityBytes
}

Expand Down
1 change: 1 addition & 0 deletions pkg/manager-nnf/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ func (s *StorageService) Initialize(log ec.Logger, ctrl NnfControllerInterface)
// Create the key-value storage database
{
path := "nnf.db"
persistent.SetLogger(log)
s.store, err = persistent.Open(path, false)
if err != nil {
log.Error(err, "Unable to open database", "path", path)
Expand Down
Loading
Loading