Skip to content

Commit

Permalink
docs: add user install doc (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
junfengP authored Oct 16, 2023
1 parent a3e0bb6 commit 38ec8ac
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 5 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ The current version defines CRDs as follows:

## Quick Start
### Deploy Nacos Controller
// TBD
1. Install helm,see [document](https://helm.sh/docs/intro/install/)
2. Install Nacos Controller
```bash
git clone https://github.com/nacos-group/nacos-controller.git
cd nacos-controller/charts/nacos-controller

export KUBECONFIG=/path/to/your/kubeconfig/file
kubectl create ns nacos
helm install -n nacos nacos-controller .
```

### Sync configuration from Kubernetes to Nacos Server
1. a Secret contains authorization information of nacos server, which is ak and sk
Expand Down
11 changes: 10 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@

## 快速开始
### 部署Nacos Controller
// TBD
1. 安装helm,参考[文档](https://helm.sh/docs/intro/install/)
2. 安装Nacos Controller
```bash
git clone https://github.com/nacos-group/nacos-controller.git
cd nacos-controller/charts/nacos-controller

export KUBECONFIG=/你的K8s集群/访问凭证/文件路径
kubectl create ns nacos
helm install -n nacos nacos-controller .
```

### 从集群中同步配置到Nacos中
1. 一份Secret配置Nacos Server访问凭证,需包含ak和sk字段
Expand Down
2 changes: 1 addition & 1 deletion charts/nacos-controller/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ image:
repository: nacos/nacos-controller
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "latest"
tag: "main"

imagePullSecrets: []

Expand Down
75 changes: 74 additions & 1 deletion pkg/controller/dynamicconfiguration_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,79 @@ var _ = Describe("DynamicConfigurationController", func() {
return true
}, time.Second*30, time.Second*5).Should(gomega.BeTrue())
})
It("With spec.ObjectRef", func() {
rand.Seed(time.Now().Unix() + 2)
randInt := rand.Int()
dataId := fmt.Sprintf("randon-data-id-%d", randInt)
content := fmt.Sprintf("content-%d", randInt)
group := fmt.Sprintf("suite-test-group-s2c-%d", randInt)
cm := v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "dc-suite-test-s2c-with-obj-ref",
Namespace: dcTestNamespaceStr,
},
}
dcWithObjRef := v12.DynamicConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "dc-suite-test-s2c-with-obj-ref",
Namespace: dcTestNamespaceStr,
},
Spec: v12.DynamicConfigurationSpec{
DataIds: []string{dataId},
Strategy: v12.SyncStrategy{
SyncPolicy: v12.Always,
SyncDeletion: true,
SyncDirection: v12.Server2Cluster,
},
NacosServer: v12.NacosServerConfiguration{
Endpoint: pointer.String(os.Getenv(nacosServerEndpoint)),
Namespace: os.Getenv(nacosServerNamespace),
Group: group,
AuthRef: &v1.ObjectReference{
Name: dcTestNacosCredentialName,
APIVersion: "v1",
Kind: "Secret",
},
},
ObjectRef: &v1.ObjectReference{
Name: cm.Name,
APIVersion: "v1",
Kind: "ConfigMap",
},
},
}
By("create dataId and content in nacos server")
createOrUpdateContentInNaocs(&dcWithObjRef, dataId, content)
By("create a DynamicConfiguration with server2cluster sync direction")
ensureDynamicConfigurationExist(&dcWithObjRef)
ensureConfigMapExist(&cm)
By(fmt.Sprintf("check configmap: %s for content: %s", cm.Name, content))
gomega.Eventually(checkConfigMapWithDataIdAndContent).
WithArguments(cm.Name, dcWithObjRef.Namespace, dataId, content).
WithTimeout(30 * time.Second).
WithPolling(5 * time.Second).
Should(gomega.BeTrue())
By("delete dataId in nacos server")
deleteDataIdInNaocs(&dcWithObjRef, dataId)
By("delete DynamicConfiguration & ConfigMap")
gomega.Expect(k8sClient.Delete(ctx, &dcWithObjRef)).Should(gomega.Succeed())
gomega.Expect(k8sClient.Delete(ctx, &cm)).Should(gomega.Succeed())
gomega.Eventually(func() bool {
v := v12.DynamicConfiguration{}
if err := k8sClient.Get(ctx, types.NamespacedName{Name: dcWithObjRef.Name, Namespace: dcWithObjRef.Namespace}, &v); err == nil {
return false
} else {
gomega.Expect(errors.IsNotFound(err)).Should(gomega.BeTrue())
}
m := v1.ConfigMap{}
if err := k8sClient.Get(ctx, types.NamespacedName{Name: cm.Name, Namespace: cm.Namespace}, &m); err == nil {
return false
} else {
gomega.Expect(errors.IsNotFound(err)).Should(gomega.BeTrue())
}
return true
}, time.Second*30, time.Second*5).Should(gomega.BeTrue())
})
})
})

Expand Down Expand Up @@ -347,7 +420,7 @@ func createOrUpdateContentInNaocs(dc *v12.DynamicConfiguration, dataId, content
}

func deleteDataIdInNaocs(dc *v12.DynamicConfiguration, dataId string) {
configClient, err := auth.GetNacosAuthManger().GetNacosConfigClient(&auth.DefaultNaocsAuthProvider{}, dc)
configClient, err := auth.GetNacosAuthManger().GetNacosConfigClient(&auth.DefaultNaocsAuthProvider{Client: k8sClient}, dc)
gomega.Expect(err).NotTo(gomega.HaveOccurred())
_, err = configClient.DeleteConfig(vo.ConfigParam{
Group: dc.Spec.NacosServer.Group,
Expand Down
2 changes: 1 addition & 1 deletion pkg/nacos/nacos_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (scc *SyncConfigurationController) syncServer2Cluster(ctx context.Context,
APIVersion: apiVersion,
}
} else {
objectRef = *(objectRef.DeepCopy())
objectRef = *(dc.Spec.ObjectRef.DeepCopy())
objectRef.Namespace = dc.Namespace
}
dc.Status.ObjectRef = &objectRef
Expand Down

0 comments on commit 38ec8ac

Please sign in to comment.