Skip to content

Commit

Permalink
Merge pull request #14 from doyoubi/FixNamespace
Browse files Browse the repository at this point in the history
Fix operator and crd can't be deployed in different namespace
  • Loading branch information
doyoubi authored Nov 15, 2020
2 parents 36778a8 + 5b1ee9b commit d224758
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Current Operator version
VERSION ?= v0.1.1
VERSION ?= v0.1.2
# Default bundle image tag
BUNDLE_IMG ?= controller-bundle:$(VERSION)
# Options for 'bundle-build'
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,27 @@ using [operator-sdk](https://sdk.operatorframework.io/).
```

Then you can see the following packages in the current directory:
- undermoon-operator-0.1.1.tgz
- undermoon-cluster-0.1.1.tgz
- undermoon-operator-0.1.2.tgz
- undermoon-cluster-0.1.2.tgz

### Run the Operator
Run the `undermoon-operator`:
Note that you can change the name `my-undermoon-operator`.
```
> helm install my-undermoon-operator undermoon-operator-0.1.1.tgz
> helm install my-undermoon-operator undermoon-operator-0.1.2.tgz
```

### Create an Undermoon Cluster
Create an undermoon cluster by installing helm charts package:
```
> helm install my-cluster \
> helm install \
--set 'cluster.clusterName=my-cluster-name' \
--set 'cluster.chunkNumber=1' \
--set 'cluster.maxMemory=50' \
--set 'cluster.port=5299' \
undermoon-cluster-0.1.1.tgz
my-cluster \
-n my-namespace \
undermoon-cluster-0.1.2.tgz
```

Fields here:
Expand Down
4 changes: 4 additions & 0 deletions config/manager/bases/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ spec:
env:
- name: GIN_MODE
value: "release"
- name: UNDERMOON_OPERATOR_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
resources:
limits:
cpu: 100m
Expand Down
2 changes: 1 addition & 1 deletion config/manager/overlays/test/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resources:
images:
- name: controller
newName: localhost:5000/undermoon-operator
newTag: v0.1.1
newTag: v0.1.2

patchesJson6902:
- target:
Expand Down
2 changes: 1 addition & 1 deletion controllers/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ func createBrokerStatefulSet(cr *undermoonv1alpha1.Undermoon) *appsv1.StatefulSe
},
{
Name: "UNDERMOON_HTTP_STORAGE_ADDRESS",
Value: fmt.Sprintf("%s:%d", metaServiceHost, metaServicePort),
Value: fmt.Sprintf("%s:%d", metaServiceHost(), metaServicePort),
},
{
Name: "UNDERMOON_REFRESH_INTERVAL",
Expand Down
11 changes: 9 additions & 2 deletions controllers/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controllers

import (
"fmt"
"os"
"strings"

pkgerrors "github.com/pkg/errors"
Expand All @@ -16,8 +17,9 @@ const (
metaStoreKey = "broker_meta_store"
metaPasswordKey = "broker_meta_password"
// The service is provided by this operator.
metaServiceHost = "undermoon-operator-storage"
metaServicePort = 9999
metaServiceName = "undermoon-operator-storage"
metaServicePort = 9999
operatorNamespaceEnvVarName = "UNDERMOON_OPERATOR_NAMESPACE"
)

func createMetaConfigMap(cr *undermoonv1alpha1.Undermoon, initData string) *corev1.ConfigMap {
Expand Down Expand Up @@ -80,6 +82,11 @@ func brokerStorageName(undermoonName, namespace string) string {
return fmt.Sprintf("%s@%s", undermoonName, namespace)
}

func metaServiceHost() string {
namespace := os.Getenv(operatorNamespaceEnvVarName)
return fmt.Sprintf("%s.%s.svc.cluster.local", metaServiceName, namespace)
}

func extractStorageName(name string) (string, string, error) {
segs := strings.SplitN(name, "@", 2)
if len(segs) != 2 {
Expand Down
10 changes: 5 additions & 5 deletions helm/undermoon-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ cluster:

image:
undermoonImage: doyoubi/undermoon
undermoonImageTag: 0.4.1
undermoonImageTag: 0.4.1-buster
undermoonImagePullPolicy: IfNotPresent
redisImage: redis
redisImageTag: 5.0.9
Expand All @@ -21,19 +21,19 @@ resources:
brokerResources:
limits:
{}
# cpu: "0.05"
# memory: "1G"
coordinatorResources:
limits:
{}
# cpu: "0.05"
# memory: "1G"
proxyResources:
limits:
{}
# cpu: "0.05"
# memory: "1G"
redisResources:
limits:
{}
# cpu: "0.05"
# memory: "5G"

nameOverride: ""
fullnameOverride: ""
2 changes: 1 addition & 1 deletion helm/undermoon-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ version: 0.1.2
# follow Semantic Versioning. They should reflect the version the application is using.
#
# This should be the same as the version of undermoon-operator.
appVersion: v0.1.1
appVersion: v0.1.2
4 changes: 4 additions & 0 deletions helm/undermoon-operator/templates/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ spec:
env:
- name: GIN_MODE
value: release
- name: UNDERMOON_OPERATOR_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: '{{ .Values.image.operatorImage }}:{{ .Values.image.operatorImageTag }}'
imagePullPolicy: '{{ .Values.image.operatorImagePullPolicy }}'
name: manager
Expand Down
2 changes: 1 addition & 1 deletion helm/undermoon-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

image:
operatorImage: doyoubi/undermoon-operator
operatorImageTag: v0.1.1
operatorImageTag: v0.1.2
operatorImagePullPolicy: IfNotPresent

nameOverride: ""
Expand Down

0 comments on commit d224758

Please sign in to comment.