Skip to content

Commit

Permalink
Merge pull request #353 from nacos-group/develop
Browse files Browse the repository at this point in the history
Optimize database initialization to read remote SQL files directly.
  • Loading branch information
paderlol authored Nov 8, 2022
2 parents edb5247 + 608e01b commit 27422e4
Show file tree
Hide file tree
Showing 13 changed files with 773 additions and 239 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/operator-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Publish Docker image

on:
push:
tags:
- 'v*'

jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
with:
images: nacos/nacos-operator

- name: Build and push Docker image
uses: docker/[email protected]
with:
context: operator
file: operator/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 1 addition & 1 deletion operator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ COPY main.go main.go
COPY api/ api/
COPY controllers/ controllers/
COPY pkg/ pkg/
COPY config/sql/nacos-mysql.sql config/sql/nacos-mysql.sql
ADD https://raw.githubusercontent.com/alibaba/nacos/develop/distribution/conf/mysql-schema.sql config/sql/nacos-mysql.sql

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -v -o manager main.go
Expand Down
4 changes: 2 additions & 2 deletions operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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)
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion) if kubernetes 1.22 later please update CRD_OPTIONS ?= "crd:crdVersions=v1"
CRD_OPTIONS ?= "crd:trivialVersions=true"

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
Expand Down Expand Up @@ -61,7 +61,7 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi

# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases

# Run go fmt against code
fmt:
Expand Down
23 changes: 19 additions & 4 deletions operator/api/v1alpha1/nacos_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ limitations under the License.
package v1alpha1

import (
"encoding/json"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"nacos.io/nacos-operator/pkg/util/merge/api"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
Expand Down Expand Up @@ -51,12 +51,27 @@ type NacosSpec struct {
// 配置文件
Config string `json:"config,omitempty"`
// 通用k8s配置包装器
K8sWrapper k8sWrapper `json:"k8sWrapper,omitempty"`
K8sWrapper K8sWrapper `json:"k8sWrapper,omitempty"`
}

type k8sWrapper struct {
PodSpec api.PodSpecWrapper `json:"PodSpec,omitempty"`
type K8sWrapper struct {
PodSpec PodSpecWrapper `json:"PodSpec,omitempty"`
}

type PodSpecWrapper struct {
Spec v1.PodSpec `json:"-"`
}

// MarshalJSON defers JSON encoding to the wrapped map
func (m *PodSpecWrapper) MarshalJSON() ([]byte, error) {
return json.Marshal(m.Spec)
}

// UnmarshalJSON will decode the data into the wrapped map
func (m *PodSpecWrapper) UnmarshalJSON(data []byte) error {
return json.Unmarshal(data, &m.Spec)
}

type Storage struct {
Enabled bool `json:"enabled,omitempty"`
Requests v1.ResourceList `json:"requests,omitempty" protobuf:"bytes,2,rep,name=requests,casttype=ResourceList,castkey=ResourceName"`
Expand Down
33 changes: 33 additions & 0 deletions operator/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 27422e4

Please sign in to comment.