Skip to content

Commit

Permalink
fix: fix controllers' makefile & docker configs
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Sep 21, 2022
1 parent 6ad8512 commit 022c4ed
Show file tree
Hide file tree
Showing 36 changed files with 401 additions and 296 deletions.
1 change: 0 additions & 1 deletion controllers/application/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore build and test binaries.
bin/
testbin/
26 changes: 5 additions & 21 deletions controllers/application/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
# Build the manager binary
FROM golang:1.18 as builder
FROM alpine:3.16.2

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
ARG TARGETARCH

# Copy the go source
COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/
WORKDIR /root

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
COPY bin /bin

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .
USER 65532:65532
RUN cp /bin/manager-$TARGETARCH /manager && rm -rf /bin

ENTRYPOINT ["/manager"]
6 changes: 4 additions & 2 deletions controllers/application/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

# Image URL to use all building/pushing image targets
IMG ?= controller:latest
IMG ?= application-controller:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.24.1

Expand Down Expand Up @@ -63,7 +63,9 @@ test: manifests generate fmt vet envtest ## Run tests.

.PHONY: build
build: generate fmt vet ## Build manager binary.
go build -o bin/manager main.go
#go build -o bin/manager main.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o bin/manager-amd64 main.go
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -a -o bin/manager-arm64 main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
Expand Down
2 changes: 1 addition & 1 deletion controllers/application/api/v1/application_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ limitations under the License.
package v1

import (
runtimev1 "github.com/labring/laf/controllers/runtime/api/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtimev1 "laf/controllers/runtime/api/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Expand Down

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions controllers/application/controllers/application_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ package controllers

import (
"context"
runtimev1 "laf/controllers/runtime/api/v1"
"laf/pkg/common"
"laf/pkg/util"
runtimev1 "github.com/labring/laf/controllers/runtime/api/v1"
"github.com/labring/laf/pkg/common"
"github.com/labring/laf/pkg/util"

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"

applicationv1 "laf/controllers/application/api/v1"
applicationv1 "github.com/labring/laf/controllers/application/api/v1"
)

const ApplicationFinalizer = "application.finalizers.laf.dev"
Expand Down
2 changes: 1 addition & 1 deletion controllers/application/controllers/bundle_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package controllers

import (
"context"
"laf/pkg/util"
"github.com/labring/laf/pkg/util"

"k8s.io/apimachinery/pkg/runtime"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ package controllers
import (
"context"
applicationv1 "github.com/labring/laf/controllers/application/api/v1"
"github.com/labring/laf/pkg/common"
"github.com/labring/laf/pkg/util"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"laf/pkg/common"
"laf/pkg/util"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log"
Expand Down
7 changes: 7 additions & 0 deletions controllers/application/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,10 @@ require (
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)


require (
github.com/labring/laf v0.0.0-00010101000000-000000000000
)

replace github.com/labring/laf => ../..
1 change: 0 additions & 1 deletion controllers/database/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore build and test binaries.
bin/
testbin/
26 changes: 5 additions & 21 deletions controllers/database/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
# Build the manager binary
FROM golang:1.18 as builder
FROM alpine:3.16.2

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download
ARG TARGETARCH

# Copy the go source
COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/
WORKDIR /root

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o manager main.go
COPY bin /bin

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .
USER 65532:65532
RUN cp /bin/manager-$TARGETARCH /manager && rm -rf /bin

ENTRYPOINT ["/manager"]
6 changes: 4 additions & 2 deletions controllers/database/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

# Image URL to use all building/pushing image targets
IMG ?= controller:latest
IMG ?= database-controller:latest
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.24.1

Expand Down Expand Up @@ -63,7 +63,9 @@ test: manifests generate fmt vet envtest ## Run tests.

.PHONY: build
build: generate fmt vet ## Build manager binary.
go build -o bin/manager main.go
#go build -o bin/manager main.go
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o bin/manager-amd64 main.go
CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -a -o bin/manager-arm64 main.go

.PHONY: run
run: manifests generate fmt vet ## Run a controller from your host.
Expand Down
4 changes: 4 additions & 0 deletions controllers/database/api/v1/database_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ type DatabaseSpec struct {
//+kubebuilder:validation:Required
Provider string `json:"provider"`

// Region of the database.
//+kubebuilder:validation:Required
Region string `json:"region"`

// Capacity desired.
//+kubebuilder:validation:Required
Capacity DatabaseCapacity `json:"capacity"`
Expand Down
2 changes: 1 addition & 1 deletion controllers/database/config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ spec:
- /manager
args:
- --leader-elect
image: controller:latest
image: database-controller:latest
name: manager
securityContext:
allowPrivilegeEscalation: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ metadata:
appid: appid-1
spec:
provider: mongodb
region: default
username: appid-1
password: password123password123
capacity:
Expand Down
2 changes: 0 additions & 2 deletions controllers/database/config/samples/mongo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ kind: Service
apiVersion: v1
metadata:
name: mongo
# namespace: laf-system
spec:
# clusterIP: None
selector:
Expand All @@ -19,7 +18,6 @@ apiVersion: apps/v1
kind: StatefulSet
metadata:
name: mongo
# namespace: laf-system
labels:
app: mongo
spec:
Expand Down
11 changes: 8 additions & 3 deletions controllers/database/controllers/database_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ package controllers
import (
"context"
"errors"
v1 "github.com/labring/laf/controllers/database/api/v1"
"github.com/labring/laf/controllers/database/dbm"
"github.com/labring/laf/pkg/util"
"k8s.io/apimachinery/pkg/runtime"
v1 "laf/controllers/database/api/v1"
"laf/controllers/database/dbm"
"laf/pkg/util"
"net/url"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -200,6 +200,11 @@ func (r *DatabaseReconciler) selectStore(ctx context.Context, database *v1.Datab
// - have the higher priority
var store v1.Store
for _, s := range storeList.Items {
// skip if the region is not match
if s.Spec.Region != database.Spec.Region {
continue
}

// skip if the provider is not match
if s.Spec.Provider != database.Spec.Provider {
continue
Expand Down
46 changes: 27 additions & 19 deletions controllers/database/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ go 1.18

require (
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.18.1
k8s.io/apimachinery v0.24.0
k8s.io/client-go v0.24.0
github.com/onsi/gomega v1.20.1
k8s.io/apimachinery v0.25.1
k8s.io/client-go v0.25.1
sigs.k8s.io/controller-runtime v0.12.1
)

require (
cloud.google.com/go v0.81.0 // indirect
cloud.google.com/go v0.97.0 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.18 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.13 // indirect
github.com/Azure/go-autorest/autorest v0.11.27 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.20 // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
Expand All @@ -24,20 +24,22 @@ require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-logr/logr v1.2.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/zapr v1.2.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.1 // indirect
github.com/golang/snappy v0.0.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.5 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/imdario/mergo v0.3.12 // indirect
Expand All @@ -62,32 +64,38 @@ require (
github.com/xdg-go/scram v1.1.1 // indirect
github.com/xdg-go/stringprep v1.0.3 // indirect
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
go.mongodb.org/mongo-driver v1.10.1 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.19.1 // indirect
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.27.1 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.24.0 // indirect
k8s.io/api v0.25.1 // indirect
k8s.io/apiextensions-apiserver v0.24.0 // indirect
k8s.io/component-base v0.24.0 // indirect
k8s.io/klog/v2 v2.60.1 // indirect
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
k8s.io/klog/v2 v2.70.1 // indirect
k8s.io/kube-openapi v0.0.0-20220803162953-67bda5d908f1 // indirect
k8s.io/utils v0.0.0-20220728103510-ee6ede2d64ed // indirect
sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

require (
github.com/labring/laf v0.0.0-00010101000000-000000000000
go.mongodb.org/mongo-driver v1.10.1
)

replace github.com/labring/laf => ../..
Loading

0 comments on commit 022c4ed

Please sign in to comment.