Skip to content

Commit 4a53e56

Browse files
authored
Feat: project initiation (#1)
1 parent 1f960a7 commit 4a53e56

File tree

311 files changed

+34235
-32
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

311 files changed

+34235
-32
lines changed

.github/workflows/ci-build.yml

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,45 @@
44
name: CI-Build
55

66
on:
7-
push:
8-
branches:
9-
- main
10-
- release-*
11-
pull_request:
12-
branches:
13-
- main
14-
- release-*
7+
release:
8+
types:
9+
- published
1510

1611
jobs:
1712
build-docker-images:
1813
runs-on: ubuntu-latest
1914
steps:
2015
- uses: actions/checkout@v4
2116

22-
- name: Get the version
17+
- name: Get Short SHA
18+
id: slug
19+
run: echo "git_revision=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
20+
21+
- name: Get Version
2322
id: get_version
2423
run: |
25-
VERSION=${GITHUB_REF#refs/tags/}
24+
if [[ "${{ github.ref_name }}" =~ ^[.\|v][0-9]{1,}.[0-9]{1,}[.\|-][0-9]{1,} ]];then
25+
VERSION=${{ github.ref_name }}
26+
else
27+
VERSION="latest"
28+
fi
2629
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
2730
28-
- name: Get image registry
29-
id: get_image_registry
30-
run: |
31-
echo "IMG_REGISTRY=${{ secrets.NX_ALIYUN_REGISTRY }}" >> $GITHUB_OUTPUT
32-
33-
# - name: Docker Login
34-
# uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
35-
# with:
36-
# registry: ${{ secrets.NX_ALIYUN_REGISTRY }}
37-
# username: ${{ secrets.NX_ALIYUN_USERNAME }}
38-
# password: ${{ secrets.NX_ALIYUN_PASSWORD }}
39-
40-
# - name: Build Images
41-
# run: make docker-build-apiserver IMG_REGISTRY=${{ steps.get_image_registry.outputs.IMG_REGISTRY }} VERSION=${{ steps.get_version.outputs.VERSION }}
42-
#
43-
# - name: Push Images
44-
# run: make docker-push-apiserver IMG_REGISTRY=${{ steps.get_image_registry.outputs.IMG_REGISTRY }} VERSION=${{ steps.get_version.outputs.VERSION }}
4531
32+
- name: Docker Login
33+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
34+
with:
35+
username: ${{ secrets.REG_USER }}
36+
password: ${{ secrets.REG_PASSWD }}
4637

38+
- name: Build Images
39+
run: |
40+
if [[ "${{ github.ref_name }}" =~ ^[.\|v][0-9]{1,}.[0-9]{1,}[.\|-][0-9]{1,} ]];then
41+
GIT_VERSION=${{ github.ref_name }}
42+
else:
43+
GIT_VERSION=${{ steps.slug.outputs.git_revision }}
44+
fi
45+
make docker-build IMG_REGISTRY=${{ secrets.CONTAINER_REGISTRY }} VERSION=${{ steps.get_version.outputs.VERSION }}
46+
47+
- name: Push Images
48+
run: make docker-push IMG_REGISTRY=${{ secrets.CONTAINER_REGISTRY }} VERSION=${{ steps.get_version.outputs.VERSION }}

.github/workflows/ci-chart.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Publish Chart
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
publish-charts:
13+
env:
14+
HELM_CHART_DIR: charts/kdp-oam-operator
15+
16+
runs-on: ubuntu-22.04
17+
steps:
18+
- uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
19+
20+
- name: Get Version
21+
id: get_version
22+
run: |
23+
CHART_VERSION=${GITHUB_REF#refs/tags/}
24+
echo "CHART_VERSION=${CHART_VERSION}" >> $GITHUB_OUTPUT
25+
26+
- name: Install Helm
27+
uses: azure/setup-helm@5119fcb9089d432beecbf79bb2c7915207344b78
28+
with:
29+
version: v3.8.2
30+
31+
- name: Docker Login
32+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
33+
with:
34+
username: ${{ secrets.REG_USER }}
35+
password: ${{ secrets.REG_PASSWD }}
36+
37+
- name: Tag helm chart and push to registry
38+
run: |
39+
chart_version=${{ steps.get_version.outputs.CHART_VERSION }}
40+
sed -i "s/v1.0.0/${chart_version}/g" $HELM_CHART_DIR/Chart.yaml
41+
helm package ./charts/kdp-oam-operator
42+
helm push kdp-oam-operator-chart-${chart_version}.tgz oci://${{ secrets.CONTAINER_REGISTRY }}/linktimecloud

.github/workflows/unit-test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ permissions:
1616

1717
env:
1818
# Common versions
19-
GO_VERSION: "1.21"
19+
GO_VERSION: "1.19"
2020

2121
jobs:
2222
detect-noop:
@@ -58,5 +58,5 @@ jobs:
5858
key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
5959
restore-keys: ${{ runner.os }}-pkg-
6060

61-
# - name: Run Make test
62-
# run: make test
61+
- name: Run Make test
62+
run: make test

Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Build the manager binary
2+
FROM golang:1.19 as builder
3+
ARG TARGETOS
4+
ARG TARGETARCH
5+
ARG VERSION
6+
ARG GITVERSION
7+
8+
WORKDIR /workspace
9+
# Copy the Go Modules manifests
10+
COPY go.mod go.mod
11+
COPY go.sum go.sum
12+
# cache deps before building and copying source so that we don't need to re-download as much
13+
# and so that source changes don't invalidate our downloaded layer
14+
15+
# It's a proxy for CN developer, please unblock it if you have network issue
16+
#ARG GOPROXY
17+
#ENV GOPROXY=${GOPROXY:-https://goproxy.cn}
18+
19+
RUN go mod download
20+
21+
# Copy the go source
22+
COPY api/ api/
23+
COPY cmd/ cmd/
24+
COPY pkg/ pkg/
25+
COPY version/ version/
26+
27+
# Build
28+
# the GOARCH has not a default value to allow the binary be built according to the host where the command
29+
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
30+
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
31+
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
32+
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -ldflags "-s -w -X kdp-oam-operator/version.CoreVersion=${VERSION:-undefined} -X kdp-oam-operator/version.GitRevision=${GITVERSION:-undefined}" -o manager cmd/bdc/main.go
33+
34+
# Use distroless as minimal base image to package the manager binary
35+
# Refer to https://github.com/GoogleContainerTools/distroless for more details
36+
FROM ${BASE_IMAGE:-alpine:3.15}
37+
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
38+
apk add --no-cache ca-certificates tzdata bash expat && \
39+
rm -rf /var/cache/apk/*
40+
41+
ENV TZ=${TZ:-Asia/Shanghai}
42+
RUN cp /usr/share/zoneinfo/${TZ} /etc/localtime
43+
RUN echo ${TZ} > /etc/timezone
44+
WORKDIR /
45+
46+
COPY --from=builder /workspace/manager .
47+
USER 65532:65532
48+
49+
ENTRYPOINT ["/manager"]

Makefile

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
include makefiles/const.mk
2+
include makefiles/build-image.mk
3+
include makefiles/build-swagger.mk
4+
include makefiles/build-bundle.mk
5+
include makefiles/build-catalog.mk
6+
include makefiles/build-helm-package.mk
7+
include makefiles/dependency.mk
8+
9+
# VERSION defines the project version for the bundle.
10+
# Update this value when you upgrade the version of your project.
11+
# To re-generate a bundle for another specific version without changing the standard setup, you can:
12+
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
13+
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
14+
VERSION ?= 0.0.1
15+
16+
.PHONY: all
17+
all: build
18+
19+
##@ General
20+
21+
# The help target prints out all targets with their descriptions organized
22+
# beneath their categories. The categories are represented by '##@' and the
23+
# target descriptions by '##'. The awk commands is responsible for reading the
24+
# entire set of makefiles included in this invocation, looking for lines of the
25+
# file as xyz: ## something, and then pretty-format the target and help. Then,
26+
# if there's a line with ##@ something, that gets pretty-printed as a category.
27+
# More info on the usage of ANSI control characters for terminal formatting:
28+
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
29+
# More info on the awk command:
30+
# http://linuxcommand.org/lc3_adv_awk.php
31+
32+
.PHONY: help
33+
help: ## Display this help.
34+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
35+
36+
##@ Development
37+
cli: ## Generate bdcctl cli.
38+
go build -o bdcctl reference/cmd/cli/main.go
39+
40+
.PHONY: manifests
41+
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
42+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./api/..." output:crd:artifacts:config=config/crd/bases
43+
44+
.PHONY: cp
45+
cp: ## Copy CRD files to helm chart.
46+
cp -r config/crd/bases/*.yaml charts/kdp-oam-operator/crds
47+
48+
.PHONY: generate
49+
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
50+
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
51+
52+
.PHONY: fmt
53+
fmt: ## Run go fmt against code.
54+
go fmt ./...
55+
56+
.PHONY: vet
57+
vet: ## Run go vet against code.
58+
go vet ./...
59+
60+
61+
.PHONY: test
62+
test: manifests generate cp fmt vet env-test ## Run tests.
63+
KUBEBUILDER_ASSETS="$(shell $(ENV_TEST) use $(ENV_TEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test $(shell go list ./pkg/...) -coverprofile cover.out && go tool cover -func=cover.out
64+
$(ENV_TEST) cleanup $(ENV_TEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path
65+
66+
.PHONY: clean
67+
clean: ## clean up env-test binary.
68+
if [[ -d $(LOCALBIN)/k8s ]]; then \
69+
rm -rf $(LOCALBIN)/k8s; \
70+
fi
71+
72+
73+
##@ Deployment
74+
75+
.PHONY: build
76+
build: manifests generate fmt vet ## Build manager binary.
77+
go build -o bin/manager cmd/bdc/main.go
78+
79+
.PHONY: run
80+
run: manifests generate fmt vet ## Run a controller from your host.
81+
go run cmd/bdc/main.go
82+
83+
ifndef ignore-not-found
84+
ignore-not-found = false
85+
endif
86+
87+
.PHONY: install
88+
install: manifests kustomize ## Install CRDs into the K8s cluster specified in ~/.kube/config.
89+
$(KUSTOMIZE) build config/crd | kubectl apply -f -
90+
91+
92+
.PHONY: uninstall
93+
uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
94+
$(KUSTOMIZE) build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
95+
96+
.PHONY: deploy
97+
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
98+
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG_CONTROLLER}
99+
$(KUSTOMIZE) build config/default | kubectl apply -f -
100+
101+
.PHONY: undeploy
102+
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
103+
$(KUSTOMIZE) build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
104+
105+
.PHONY: apply
106+
apply: manifests kustomize ## Apply samples into the K8s cluster specified in ~/.kube/config.
107+
$(KUSTOMIZE) build config/samples | kubectl apply -f -
108+
109+
.PHONY: delete
110+
delete: manifests kustomize ## Delete samples from the K8s cluster specified in ~/.kube/config.
111+
$(KUSTOMIZE) build config/samples | kubectl delete -f -
112+
113+
.PHONY: run-apiserver
114+
run-apiserver: fmt vet ## Run a api server from your host.
115+
go run cmd/apiserver/main.go --kube-api-qps=300 --kube-api-burst=900

PROJECT

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Code generated by tool. DO NOT EDIT.
2+
# This file is used to track the info used to scaffold your project
3+
# and allow the plugins properly work.
4+
# More info: https://book.kubebuilder.io/reference/project-config.html
5+
domain: kdp.io
6+
layout:
7+
- go.kubebuilder.io/v3
8+
plugins:
9+
manifests.sdk.operatorframework.io/v2: {}
10+
scorecard.sdk.operatorframework.io/v2: {}
11+
projectName: kdp-oam-operator
12+
repo: kdp-oam-operator
13+
resources:
14+
- api:
15+
crdVersion: v1
16+
controller: true
17+
domain: kdp.io
18+
group: bdc
19+
kind: BigDataCluster
20+
path: kdp-oam-operator/api/v1alpha1
21+
version: v1alpha1
22+
webhooks:
23+
defaulting: true
24+
validation: true
25+
webhookVersion: v1
26+
- api:
27+
crdVersion: v1
28+
controller: true
29+
domain: kdp.io
30+
group: bdc
31+
kind: ContextSecret
32+
path: kdp-oam-operator/api/v1alpha1
33+
version: v1alpha1
34+
webhooks:
35+
defaulting: true
36+
validation: true
37+
webhookVersion: v1
38+
- api:
39+
crdVersion: v1
40+
controller: true
41+
domain: kdp.io
42+
group: bdc
43+
kind: ContextSetting
44+
path: kdp-oam-operator/api/v1alpha1
45+
version: v1alpha1
46+
webhooks:
47+
defaulting: true
48+
validation: true
49+
webhookVersion: v1
50+
- api:
51+
crdVersion: v1
52+
controller: true
53+
domain: kdp.io
54+
group: bdc
55+
kind: XDefinition
56+
path: kdp-oam-operator/api/v1alpha1
57+
version: v1alpha1
58+
- api:
59+
crdVersion: v1
60+
controller: true
61+
domain: kdp.io
62+
group: bdc
63+
kind: Application
64+
path: kdp-oam-operator/api/v1alpha1
65+
version: v1alpha1
66+
version: "3"

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,20 @@
1-
# template-project
2-
This is the template project for initializing other LTC projects.
1+
# kdp-oam-operator
2+
The kdp-oam-operator, based on the KDP (Kubernetes Data Platform) bigdata model, provides a highly programmable application-centric delivery model. It allows users to build upon the fundamental capabilities of the kdp-oam-operator to extend and customize their services. The most critical components in the kdp-oam-operator are the XDefinition, Application, BDC, ContextSetting, and ContextSecret. All of these are built upon the fundamental structure of the Kubernetes Custom Resource Definition (CRD) model and manage the resource lifecycle through the implementation of independent controller components.
3+
4+
5+
## License
6+
7+
Copyright 2023 KDP(Kubernetes Data Platform).
8+
9+
Licensed under the Apache License, Version 2.0 (the "License");
10+
you may not use this file except in compliance with the License.
11+
You may obtain a copy of the License at
12+
13+
http://www.apache.org/licenses/LICENSE-2.0
14+
15+
Unless required by applicable law or agreed to in writing, software
16+
distributed under the License is distributed on an "AS IS" BASIS,
17+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
See the License for the specific language governing permissions and
19+
limitations under the License.
20+

0 commit comments

Comments
 (0)