Skip to content

Commit

Permalink
Update structure closer to original one, bump golang
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddenmarten committed Jun 22, 2024
1 parent 2cf0661 commit a9dd402
Show file tree
Hide file tree
Showing 33 changed files with 400 additions and 907 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore build and test binaries.
bin/
14 changes: 10 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Build the manager binary
FROM golang:1.21 as builder
FROM golang:1.22 AS builder
ARG TARGETOS
ARG TARGETARCH

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -10,12 +12,16 @@ COPY go.sum go.sum
RUN go mod download

# Copy the go source
COPY main.go main.go
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY controllers/ controllers/
COPY internal/controller/ internal/controller/

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -ldflags="-s -w" -a -o manager main.go
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ endif

all: manager

.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
go build -o bin/manager cmd/main.go

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
@echo "Check for kubernetes version $(K8S_VERSION_TRIMMED_V) in $(ENVTEST)"
Expand Down Expand Up @@ -106,6 +110,7 @@ K8S_VERSION_TRIMMED_V = $(subst v,,$(K8S_VERSION))

KIND_CLUSTER_NAME ?= seaweedfs-operator-kind
NAMESPACE ?= seaweedfs-operator-system
KIND_IMAGE ?= kindest/node:$(K8S_VERSION)

# renovate: datasource=github-tags depName=prometheus-operator/prometheus-operator
PROMETHEUS_OPERATOR_VERSION ?= v0.74.0
Expand Down Expand Up @@ -136,7 +141,6 @@ undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/.

.PHONY: redeploy
redeploy: deploy ## Redeploy controller with new docker image.
# force recreate pods
$(KUBECTL) rollout restart -n $(NAMESPACE) deploy/seaweedfs-operator-controller-manager

.PHONY: kind-load
Expand All @@ -146,11 +150,11 @@ kind-load: docker-build kind ## Build and upload docker image to the local Kind
.PHONY: kind-create
kind-create: kind yq ## Create kubernetes cluster using Kind.
@if ! $(KIND) get clusters | grep -q $(KIND_CLUSTER_NAME); then \
$(KIND) create cluster --name $(KIND_CLUSTER_NAME) --image kindest/node:$(K8S_VERSION); \
$(KIND) create cluster --name $(KIND_CLUSTER_NAME) --image $(KIND_IMAGE); \
fi
@if ! $(CONTAINER_TOOL) container inspect $$($(KIND) get nodes) | $(YQ) e '.[0].Config.Image' | grep -q $(K8S_VERSION); then \
@if ! $(CONTAINER_TOOL) ps --format json | $(YQ) -P -pj e 'select(.Names == "$(KIND_CLUSTER_NAME)-control-plane") | .Image' | grep -q $(KIND_IMAGE); then \
$(KIND) delete cluster --name $(KIND_CLUSTER_NAME); \
$(KIND) create cluster --name $(KIND_CLUSTER_NAME) --image kindest/node:$(K8S_VERSION); \
$(KIND) create cluster --name $(KIND_CLUSTER_NAME) --image $(KIND_IMAGE); \
fi

.PHONY: kind-delete
Expand Down
6 changes: 3 additions & 3 deletions main.go → cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"

seaweedv1 "github.com/seaweedfs/seaweedfs-operator/api/v1"
"github.com/seaweedfs/seaweedfs-operator/controllers"
"github.com/seaweedfs/seaweedfs-operator/internal/controller"
// +kubebuilder:scaffold:imports
)

Expand Down Expand Up @@ -71,9 +71,9 @@ func main() {
os.Exit(1)
}

if err = (&controllers.SeaweedReconciler{
if err = (&controller.SeaweedReconciler{
Client: mgr.GetClient(),
Log: ctrl.Log.WithName("controllers").WithName("Seaweed"),
Log: ctrl.Log.WithName("controller").WithName("Seaweed"),
Scheme: mgr.GetScheme(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Seaweed")
Expand Down
20 changes: 13 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module github.com/seaweedfs/seaweedfs-operator

go 1.17
go 1.22

require (
github.com/go-logr/logr v1.2.3
github.com/onsi/ginkgo v1.16.5
github.com/onsi/ginkgo/v2 v2.1.4
github.com/onsi/gomega v1.20.0
github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring v0.60.1
google.golang.org/grpc v1.49.0
Expand All @@ -15,6 +16,11 @@ require (
sigs.k8s.io/controller-runtime v0.12.3
)

require (
github.com/go-resty/resty/v2 v2.13.1
github.com/moby/spdystream v0.2.0 // indirect
)

require (
cloud.google.com/go/compute v1.7.0 // indirect
github.com/aws/aws-sdk-go v1.44.95 // indirect
Expand Down Expand Up @@ -82,15 +88,15 @@ require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/image v0.0.0-20200119044424-58c23975cae1 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/oauth2 v0.0.0-20220822191816-0ebed06d0094 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/term v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/time v0.5.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc // indirect
Expand Down
Loading

0 comments on commit a9dd402

Please sign in to comment.