fix: Allow no config cluster (#4164)

* Update USERS.md

* Allow no config cluster

* Add tests

* Fix lint issues
This commit is contained in:
Daisuke Taniwaki 2020-08-27 11:50:02 +09:00 committed by GitHub
parent 9f79340505
commit 10d05cdb60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 3 deletions

View file

@ -47,6 +47,7 @@ Currently, the following organizations are **officially** using Argo CD:
1. [Optoro](https://www.optoro.com/)
1. [Peloton Interactive](https://www.onepeloton.com/)
1. [Pipefy](https://www.pipefy.com/)
1. [Preferred Networks](https://preferred.jp/en/)
1. [Prudential](https://prudential.com.sg)
1. [PUBG](https://www.pubg.com)
1. [QuintoAndar](https://quintoandar.com.br)

View file

@ -314,10 +314,13 @@ func clusterToSecret(c *appv1.Cluster, secret *apiv1.Secret) error {
// secretToCluster converts a secret into a Cluster object
func secretToCluster(s *apiv1.Secret) *appv1.Cluster {
var config appv1.ClusterConfig
err := json.Unmarshal(s.Data["config"], &config)
if err != nil {
panic(err)
if len(s.Data["config"]) > 0 {
err := json.Unmarshal(s.Data["config"], &config)
if err != nil {
panic(err)
}
}
var namespaces []string
for _, ns := range strings.Split(string(s.Data["namespaces"]), ",") {
if ns = strings.TrimSpace(ns); ns != "" {

View file

@ -25,6 +25,46 @@ func Test_serverToSecretName(t *testing.T) {
assert.Equal(t, "cluster-foo-752281925", name)
}
func Test_secretToCluster(t *testing.T) {
secret := &v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "mycluster",
Namespace: fakeNamespace,
},
Data: map[string][]byte{
"name": []byte("test"),
"server": []byte("http://mycluster"),
"config": []byte("{\"username\":\"foo\"}"),
},
}
cluster := secretToCluster(secret)
assert.Equal(t, *cluster, v1alpha1.Cluster{
Name: "test",
Server: "http://mycluster",
Config: v1alpha1.ClusterConfig{
Username: "foo",
},
})
}
func Test_secretToCluster_NoConfig(t *testing.T) {
secret := &v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Name: "mycluster",
Namespace: fakeNamespace,
},
Data: map[string][]byte{
"name": []byte("test"),
"server": []byte("http://mycluster"),
},
}
cluster := secretToCluster(secret)
assert.Equal(t, *cluster, v1alpha1.Cluster{
Name: "test",
Server: "http://mycluster",
})
}
func TestUpdateCluster(t *testing.T) {
kubeclientset := fake.NewSimpleClientset(&v1.Secret{
ObjectMeta: metav1.ObjectMeta{