Skip to content

Commit

Permalink
Prefix etcd pod and services with the vineyardd name to avoid conflic…
Browse files Browse the repository at this point in the history
…ts (#1339)

See `k8s/pkg/templates/etcd/service.yaml` and
`k8s/pkg/templates/etcd/etcd.yaml`. Refactor some unnecessary global
functions and changed the default etcd replicas to 1 as well.

---------

Signed-off-by: Tao He <[email protected]>
  • Loading branch information
sighingnow authored Apr 24, 2023
1 parent d52c77c commit 4ff47f5
Show file tree
Hide file tree
Showing 32 changed files with 192 additions and 192 deletions.
2 changes: 1 addition & 1 deletion charts/vineyard-operator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ spec:
- name: cert
secret:
defaultMode: 420
secretName: webhook-server-cert
secretName: vineyard-operator-webhook-server-cert
2 changes: 1 addition & 1 deletion charts/vineyard-operator/templates/serving-cert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ spec:
issuerRef:
kind: Issuer
name: '{{ include "vineyard-operator.fullname" . }}-selfsigned-issuer'
secretName: webhook-server-cert
secretName: vineyard-operator-webhook-server-cert
2 changes: 1 addition & 1 deletion charts/vineyard-operator/templates/sidecar-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ spec:
spec:
properties:
etcdReplicas:
default: 3
default: 1
type: integer
metric:
default:
Expand Down
2 changes: 1 addition & 1 deletion charts/vineyard-operator/templates/vineyardd-crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ spec:
spec:
properties:
etcdReplicas:
default: 3
default: 1
type: integer
metric:
default:
Expand Down
11 changes: 6 additions & 5 deletions docs/notes/cloud-native/deploy-kubernetes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,17 @@ Option #2: Install form source code
3. Install the cert-manager

.. code:: bash
.. code:: bash
$ kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.9.1/cert-manager.yaml
$ kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.9.1/cert-manager.yaml
.. note::
.. note::

Please wait the cert-manager for a while until it is ready before installing the
vineyard operator.
Please wait the cert-manager for a while until it is ready before installing the
vineyard operator.

4. Next, deploy the vineyard operator:

.. code:: bash
$ make -C k8s deploy
Expand Down
2 changes: 1 addition & 1 deletion docs/notes/cloud-native/vineyard-operator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ The detailed configuration entries for creating a vineyard cluster are listed as
* - | etcdReplicas
- int
- The etcd replicas of vineyard
- 3
- 1

* - | vineyard.
| image
Expand Down
42 changes: 21 additions & 21 deletions k8s/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ else
GOBIN=$(shell go env GOBIN)
endif

GOLINT = $(shell command -v ${GOBIN}/golangci-lint > /dev/null)
HELMIFY = $(shell command -v ${GOBIN}/helmify > /dev/null)
E2E = $(shell command -v ${GOBIN}/e2e > /dev/null)
KUSTOMIZE = $(shell command -v ${GOBIN}/kustomize > /dev/null)
CONTROLLER_GEN = $(shell command -v ${GOBIN}/controller-gen > /dev/null)
GOLINT = $(shell command -v $(GOBIN)/golangci-lint 2> /dev/null)
HELMIFY = $(shell command -v $(GOBIN)/helmify 2> /dev/null)
E2E = $(shell command -v $(GOBIN)/e2e 2> /dev/null)
KUSTOMIZE = $(shell command -v $(GOBIN)/kustomize 2> /dev/null)
CONTROLLER_GEN = $(shell command -v $(GOBIN)/controller-gen 2> /dev/null)

## Tool Versions
KUSTOMIZE_VERSION ?= [email protected]
Expand Down Expand Up @@ -91,7 +91,7 @@ uninstall: manifests kustomize
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
.PHONY: deploy
deploy: manifests kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build config/default | kubectl apply -f -

# Undeploy controller in the configured Kubernetes cluster in ~/.kube/config
Expand All @@ -102,32 +102,32 @@ undeploy: kustomize
# Undeploy controller and all created resources in the configured Kubernetes cluster in ~/.kube/config
.PHONY: undeploy-all
undeploy-all: kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build config/default | kubectl delete -f -

# Deploy namespace, CRDs, rbac, etc. except the controller in the configured Kubernetes cluster in ~/.kube/config
.PHONY: predeploy
predeploy: manifests kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)

.PHONY: unpredeploy
unpredeploy: manifests kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)

# update the operator image's registry to localhost
.PHONY: update-registry
update-registry: kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)

# recover the operator image's registry to vineyardcloudnative
.PHONY: recover-registry
recover-registry: kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)

# dump the deployment configuration
.PHONY: dry-run
dry-run: manifests kustomize
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
$(KUSTOMIZE) build config/default > controller.yaml

# Generate manifests e.g. CRD, RBAC etc.
Expand All @@ -152,7 +152,7 @@ modules = ./apis/... \
# Run golangci-lint
.PHONY: golint
golint:
ifeq (${GOLINT},)
ifeq ($(GOLINT),)
@echo "golangci-lint not exist, installing it..."
go install github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION)
endif
Expand All @@ -162,7 +162,7 @@ golint:
# Install helmify if not exist
.PHONY: helmify
helmify:
ifeq (${HELMIFY},)
ifeq ($(HELMIFY),)
@echo "helmify not exist, installing it..."
go install github.com/arttor/helmify/cmd/helmify@$(HELMIFY_VERSION)
endif
Expand All @@ -172,7 +172,7 @@ helmify:
# Install e2e if not exist
.PHONY: e2e
e2e:
ifeq (${E2E},)
ifeq ($(E2E),)
@echo "e2e not exist, installing it..."
go install github.com/apache/skywalking-infra-e2e/cmd/e2e@$(E2E_VERSION)
endif
Expand Down Expand Up @@ -210,24 +210,24 @@ vendor:
.PHONY: docker-build
docker-build:
if docker build --help | grep -q load; then \
docker build --load . -t ${IMG}; \
docker build --load . -t $(IMG); \
else \
docker build . -t ${IMG}; \
docker build . -t $(IMG); \
fi

docker-build-push-multi-arch:
docker buildx build . -t ${IMG} --platform linux/amd64,linux/arm64 --push
docker buildx build . -t $(IMG) --platform linux/amd64,linux/arm64 --push

# Push the docker image
.PHONY: docker-push
docker-push:
docker push ${IMG}
docker push $(IMG)

# find or download controller-gen
# download controller-gen if necessary
.PHONY: controller-gen
controller-gen:
ifeq (${CONTROLLER_GEN},)
ifeq ($(CONTROLLER_GEN),)
@{ \
set -e ;\
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
Expand All @@ -241,7 +241,7 @@ controller-gen:

.PHONY: kustomize
kustomize:
ifeq (${KUSTOMIZE},)
ifeq ($(KUSTOMIZE),)
@{ \
set -e ;\
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\
Expand Down
2 changes: 1 addition & 1 deletion k8s/apis/k8s/v1alpha1/sidecar_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type SidecarSpec struct {

// EtcdReplicas describe the etcd replicas
// +kubebuilder:validation:Optional
// +kubebuilder:default:=3
// +kubebuilder:default:=1
EtcdReplicas int `json:"etcdReplicas,omitempty"`

// vineyard container configuration
Expand Down
2 changes: 1 addition & 1 deletion k8s/apis/k8s/v1alpha1/vineyardd_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ type VineyarddSpec struct {

// EtcdReplicas describe the etcd replicas
// +kubebuilder:validation:Optional
// +kubebuilder:default:=3
// +kubebuilder:default:=1
EtcdReplicas int `json:"etcdReplicas,omitempty"`

// vineyardd's service
Expand Down
12 changes: 8 additions & 4 deletions k8s/cmd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ vineyardctl deploy vineyard-deployment [flags]
--pluginImage.distributedAssemblyImage string the distributed image of vineyard workflow (default "ghcr.io/v6d-io/v6d/distributed-assembly")
--pluginImage.localAssemblyImage string the local assembly image of vineyardd workflow (default "ghcr.io/v6d-io/v6d/local-assembly")
--pluginImage.recoverImage string the recover image of vineyardd (default "ghcr.io/v6d-io/v6d/recover-job")
--vineyard.etcd.replicas int the number of etcd replicas in a vineyard cluster (default 3)
--vineyard.etcd.replicas int the number of etcd replicas in a vineyard cluster (default 1)
--vineyard.replicas int the number of vineyardd replicas (default 3)
--vineyardd.envs strings The environment variables of vineyardd
--vineyardd.image string the image of vineyardd (default "vineyardcloudnative/vineyardd:latest")
Expand Down Expand Up @@ -845,7 +845,7 @@ vineyardctl deploy vineyardd [flags]
--pluginImage.distributedAssemblyImage string the distributed image of vineyard workflow (default "ghcr.io/v6d-io/v6d/distributed-assembly")
--pluginImage.localAssemblyImage string the local assembly image of vineyardd workflow (default "ghcr.io/v6d-io/v6d/local-assembly")
--pluginImage.recoverImage string the recover image of vineyardd (default "ghcr.io/v6d-io/v6d/recover-job")
--vineyard.etcd.replicas int the number of etcd replicas in a vineyard cluster (default 3)
--vineyard.etcd.replicas int the number of etcd replicas in a vineyard cluster (default 1)
--vineyard.replicas int the number of vineyardd replicas (default 3)
--vineyardd.envs strings The environment variables of vineyardd
--vineyardd.image string the image of vineyardd (default "vineyardcloudnative/vineyardd:latest")
Expand Down Expand Up @@ -875,7 +875,7 @@ Inject the vineyard sidecar container into a workload
### Synopsis

Inject the vineyard sidecar container into a workload. You can
input a workload yaml or a workload json and then get the injected
input a workload yaml or a workload json and then get the injected
workload and some etcd manifests from the output.

The output is a set of manifests that includes the injected workload,
Expand All @@ -884,6 +884,7 @@ pods and services). Next, we will introduce a simple example to show
the injection.

Assume you have the following workload yaml:

```yaml
apiVersion: apps/v1
kind: Deployment
Expand All @@ -906,12 +907,14 @@ spec:
ports:
- containerPort: 80
```
Then, you can use the following command to inject the vineyard sidecar
$ vineyardctl inject -f workload.yaml --apply-resources
After running the command, the main output(removed some unnecessary fields)
is as follows:
```yaml
apiVersion: apps/v1
kind: Deployment
Expand Down Expand Up @@ -968,6 +971,7 @@ template:
- emptyDir: {}
name: vineyard-socket
```
The sidecar template can be accessed from the following link:
https://github.com/v6d-io/v6d/blob/main/k8s/pkg/templates/sidecar/injection-template.yaml
also you can get some inspiration from the doc link:
Expand Down Expand Up @@ -1007,7 +1011,7 @@ vineyardctl inject [flags]
# inject the default vineyard sidecar container into a workload
# output all injected manifests and then deploy them
vineyardctl inject -f workload.yaml | kubectl apply -f -

# if you only want to get the injected workload yaml rather than
# all manifests that includes the etcd cluster and the rpc service,
# you can enable the apply-resources and then the manifests will be
Expand Down
2 changes: 1 addition & 1 deletion k8s/cmd/commands/flags/vineyardd_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func ApplyVineyarddOpts(cmd *cobra.Command) {
cmd.Flags().IntVarP(&VineyarddOpts.Replicas, "vineyard.replicas", "", 3,
"the number of vineyardd replicas")
cmd.Flags().IntVarP(&VineyarddOpts.EtcdReplicas, "vineyard.etcd.replicas",
"", 3, "the number of etcd replicas in a vineyard cluster")
"", 1, "the number of etcd replicas in a vineyard cluster")
cmd.Flags().StringVarP(&VineyarddFile, "file", "f", "", "the path of vineyardd")
// setup the vineyardd name
ApplyVineyarddNameOpts(cmd)
Expand Down
16 changes: 9 additions & 7 deletions k8s/cmd/commands/sidecar/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ var (

injectLong = util.LongDesc(`
Inject the vineyard sidecar container into a workload. You can
input a workload yaml or a workload json and then get the injected
input a workload yaml or a workload json and then get the injected
workload and some etcd manifests from the output.
The output is a set of manifests that includes the injected workload,
the rpc service, the etcd service and the etcd cluster(e.g. several
pods and services). Next, we will introduce a simple example to show
the injection.
Assume you have the following workload yaml:` +
"\n```yaml" + `
"\n\n```yaml" + `
apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -102,13 +102,14 @@ var (
ports:
- containerPort: 80` +
"\n```" + `
Then, you can use the following command to inject the vineyard sidecar
$ vineyardctl inject -f workload.yaml --apply-resources
After running the command, the main output(removed some unnecessary fields)
is as follows:` +
"\n```yaml" + `
"\n\n```yaml" + `
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -164,6 +165,7 @@ var (
- emptyDir: {}
name: vineyard-socket` +
"\n```" + `
The sidecar template can be accessed from the following link:
https://github.com/v6d-io/v6d/blob/main/k8s/pkg/templates/sidecar/injection-template.yaml
also you can get some inspiration from the doc link:
Expand Down Expand Up @@ -193,7 +195,7 @@ var (
# inject the default vineyard sidecar container into a workload
# output all injected manifests and then deploy them
vineyardctl inject -f workload.yaml | kubectl apply -f -
# if you only want to get the injected workload yaml rather than
# all manifests that includes the etcd cluster and the rpc service,
# you can enable the apply-resources and then the manifests will be
Expand Down
2 changes: 1 addition & 1 deletion k8s/cmd/commands/util/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func BuildObjsFromEtcdManifests(EtcdConfig *k8s.EtcdConfig, name string,
return podObjs, svcObjs, errors.Wrap(err, "failed to get etcd manifests")
}
// set up the etcd config
*EtcdConfig = k8s.BuildEtcdConfig(name, namespace, replicas, image)
*EtcdConfig = k8s.NewEtcdConfig(name, namespace, replicas, image)

for i := 0; i < replicas; i++ {
EtcdConfig.Rank = i
Expand Down
2 changes: 1 addition & 1 deletion k8s/config/certmanager/certificate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ spec:
issuerRef:
kind: Issuer
name: selfsigned-issuer
secretName: webhook-server-cert # this secret will not be prefixed, since it's not managed by kustomize
secretName: vineyard-operator-webhook-server-cert # this secret will not be prefixed, since it's not managed by kustomize
2 changes: 1 addition & 1 deletion k8s/config/crd/bases/k8s.v6d.io_sidecars.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ spec:
spec:
properties:
etcdReplicas:
default: 3
default: 1
type: integer
metric:
default:
Expand Down
2 changes: 1 addition & 1 deletion k8s/config/crd/bases/k8s.v6d.io_vineyardds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ spec:
spec:
properties:
etcdReplicas:
default: 3
default: 1
type: integer
metric:
default:
Expand Down
2 changes: 1 addition & 1 deletion k8s/config/default/manager_webhook_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ spec:
- name: cert
secret:
defaultMode: 420
secretName: webhook-server-cert
secretName: vineyard-operator-webhook-server-cert
Loading

0 comments on commit 4ff47f5

Please sign in to comment.