forked from kubesphere/kubekey
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: pixiake <guofeng@yunify.com>
- Loading branch information
Showing
97 changed files
with
1,255 additions
and
1,322 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
# Files generated by JetBrains IDEs, e.g. IntelliJ IDEA | ||
.idea/ | ||
*.iml | ||
.bin/ | ||
|
||
# Vscode files | ||
.vscode | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Build the manager binary | ||
FROM golang:1.13 as builder | ||
|
||
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 | ||
|
||
# Copy the go source | ||
COPY main.go main.go | ||
COPY api/ api/ | ||
COPY controllers/ controllers/ | ||
|
||
# Build | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go | ||
|
||
# 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 nonroot:nonroot | ||
|
||
ENTRYPOINT ["/manager"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,120 @@ | ||
SHELL = /usr/bin/env bash | ||
|
||
GIT_COMMIT = $(shell git rev-parse HEAD) | ||
GIT_SHA = $(shell git rev-parse --short HEAD) | ||
GIT_TAG = $(shell git describe --tags --abbrev=0 --exact-match 2>/dev/null) | ||
GIT_DIRTY = $(shell test -n "`git status --porcelain`" && echo "dirty" || echo "clean") | ||
|
||
VERSION_METADATA = unreleased | ||
VERSION = latest | ||
# Clear the "unreleased" string in BuildMetadata | ||
ifneq ($(GIT_TAG),) | ||
VERSION_METADATA = | ||
VERSION = ${GIT_TAG} | ||
# Current Operator version | ||
VERSION ?= 0.0.1 | ||
# Default bundle image tag | ||
BUNDLE_IMG ?= controller-bundle:$(VERSION) | ||
# Options for 'bundle-build' | ||
ifneq ($(origin CHANNELS), undefined) | ||
BUNDLE_CHANNELS := --channels=$(CHANNELS) | ||
endif | ||
ifneq ($(origin DEFAULT_CHANNEL), undefined) | ||
BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL) | ||
endif | ||
BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) | ||
|
||
# Image URL to use all building/pushing image targets | ||
IMG ?= controller:latest | ||
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion) | ||
CRD_OPTIONS ?= "crd:trivialVersions=true" | ||
|
||
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) | ||
ifeq (,$(shell go env GOBIN)) | ||
GOBIN=$(shell go env GOPATH)/bin | ||
else | ||
GOBIN=$(shell go env GOBIN) | ||
endif | ||
|
||
all: manager | ||
|
||
# Run tests | ||
test: generate fmt vet manifests | ||
go test ./... -coverprofile cover.out | ||
|
||
# Build manager binary | ||
manager: generate fmt vet | ||
go build -o bin/manager main.go | ||
|
||
# Run against the configured Kubernetes cluster in ~/.kube/config | ||
run: generate fmt vet manifests | ||
go run ./main.go | ||
|
||
# Install CRDs into a cluster | ||
install: manifests kustomize | ||
$(KUSTOMIZE) build config/crd | kubectl apply -f - | ||
|
||
# Uninstall CRDs from a cluster | ||
uninstall: manifests kustomize | ||
$(KUSTOMIZE) build config/crd | kubectl delete -f - | ||
|
||
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config | ||
deploy: manifests kustomize | ||
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} | ||
$(KUSTOMIZE) build config/default | kubectl apply -f - | ||
|
||
# Generate manifests e.g. CRD, RBAC etc. | ||
manifests: controller-gen | ||
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases | ||
|
||
# Run go fmt against code | ||
fmt: | ||
go fmt ./... | ||
|
||
# Run go vet against code | ||
vet: | ||
go vet ./... | ||
|
||
# Generate code | ||
generate: controller-gen | ||
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." | ||
|
||
# Build the docker image | ||
docker-build: test | ||
docker build . -t ${IMG} | ||
|
||
# Push the docker image | ||
docker-push: | ||
docker push ${IMG} | ||
|
||
# find or download controller-gen | ||
# download controller-gen if necessary | ||
controller-gen: | ||
ifeq (, $(shell which controller-gen)) | ||
@{ \ | ||
set -e ;\ | ||
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\ | ||
cd $$CONTROLLER_GEN_TMP_DIR ;\ | ||
go mod init tmp ;\ | ||
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.3.0 ;\ | ||
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\ | ||
} | ||
CONTROLLER_GEN=$(GOBIN)/controller-gen | ||
else | ||
CONTROLLER_GEN=$(shell which controller-gen) | ||
endif | ||
|
||
kustomize: | ||
ifeq (, $(shell which kustomize)) | ||
@{ \ | ||
set -e ;\ | ||
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\ | ||
cd $$KUSTOMIZE_GEN_TMP_DIR ;\ | ||
go mod init tmp ;\ | ||
go get sigs.k8s.io/kustomize/kustomize/v3@v3.5.4 ;\ | ||
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\ | ||
} | ||
KUSTOMIZE=$(GOBIN)/kustomize | ||
else | ||
KUSTOMIZE=$(shell which kustomize) | ||
endif | ||
|
||
# Generate bundle manifests and metadata, then validate generated files. | ||
.PHONY: bundle | ||
bundle: manifests | ||
operator-sdk generate kustomize manifests -q | ||
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG) | ||
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS) | ||
operator-sdk bundle validate ./bundle | ||
|
||
LDFLAGS += -X github.com/kubesphere/kubekey/version.version=${VERSION} | ||
LDFLAGS += -X github.com/kubesphere/kubekey/version.metadata=${VERSION_METADATA} | ||
LDFLAGS += -X github.com/kubesphere/kubekey/version.gitCommit=${GIT_COMMIT} | ||
LDFLAGS += -X github.com/kubesphere/kubekey/version.gitTreeState=${GIT_DIRTY} | ||
|
||
.PHONY: build | ||
build: build-linux-amd64 build-linux-arm64 | ||
|
||
build-linux-amd64: | ||
docker run --rm \ | ||
-v $(shell pwd):/usr/src/myapp \ | ||
-e GOOS=linux \ | ||
-e GOARCH=amd64 \ | ||
-e CGO_ENABLED=0 \ | ||
-e GO111MODULE=on \ | ||
-w /usr/src/myapp golang:1.14 \ | ||
go build -ldflags '$(LDFLAGS)' -v -o output/linux/amd64/kk ./kubekey.go # linux | ||
sha256sum output/linux/amd64/kk || shasum -a 256 output/linux/amd64/kk | ||
|
||
build-linux-arm64: | ||
docker run --rm \ | ||
-v $(shell pwd):/usr/src/myapp \ | ||
-e GOOS=linux \ | ||
-e GOARCH=arm64 \ | ||
-e CGO_ENABLED=0 \ | ||
-e GO111MODULE=on \ | ||
-w /usr/src/myapp golang:1.14 \ | ||
go build -ldflags '$(LDFLAGS)' -v -o output/linux/arm64/kk ./kubekey.go # linux | ||
sha256sum output/linux/arm64/kk || shasum -a 256 output/linux/arm64/kk | ||
# Build the bundle image. | ||
.PHONY: bundle-build | ||
bundle-build: | ||
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
domain: kubesphere.io | ||
layout: go.kubebuilder.io/v2 | ||
projectName: kubekey | ||
repo: github.com/kubesphere/kubekey | ||
resources: | ||
- group: kubekey | ||
kind: Cluster | ||
version: v1alpha1 | ||
version: 3-alpha | ||
plugins: | ||
go.sdk.operatorframework.io/v2-alpha: {} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
Copyright 2020 The KubeSphere Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// Package v1alpha1 contains API Schema definitions for the kubekey v1alpha1 API group | ||
// +kubebuilder:object:generate=true | ||
// +groupName=kubekey.kubesphere.io | ||
package v1alpha1 | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"sigs.k8s.io/controller-runtime/pkg/scheme" | ||
) | ||
|
||
var ( | ||
// GroupVersion is group version used to register these objects | ||
GroupVersion = schema.GroupVersion{Group: "kubekey.kubesphere.io", Version: "v1alpha1"} | ||
|
||
// SchemeBuilder is used to add go types to the GroupVersionKind scheme | ||
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} | ||
|
||
// AddToScheme adds the types in this group-version to the given scheme. | ||
AddToScheme = SchemeBuilder.AddToScheme | ||
) |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.