Skip to content

Commit 1b26e3f

Browse files
author
chilianyi
authored
Fix nil in log (#1035)
1 parent f0a23fe commit 1b26e3f

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

controllers/argocd/multi-cluster-controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func getArgoClusterConfigObject(configText string) (object *ClusterConfig) {
155155
rawDecodedconfig, _ := base64.StdEncoding.DecodeString(configText)
156156

157157
var kubeconfig *config
158-
if kubeconfig = parseKubeConfig(rawDecodedconfig); kubeconfig == nil {
158+
if kubeconfig, _ = parseKubeConfig(rawDecodedconfig); kubeconfig == nil {
159159
return
160160
}
161161

controllers/argocd/types.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ limitations under the License.
1919
package argocd
2020

2121
import (
22-
"fmt"
2322
"gopkg.in/yaml.v2"
2423
)
2524

@@ -58,11 +57,12 @@ type TLSClientConfig struct {
5857
CAData []byte `json:"caData,omitempty"`
5958
}
6059

61-
func parseKubeConfig(data []byte) (cfg *config) {
62-
cfg = &config{}
63-
err := yaml.Unmarshal(data, cfg)
64-
fmt.Println(err)
65-
return
60+
func parseKubeConfig(data []byte) (*config, error) {
61+
cfg := &config{}
62+
if err := yaml.Unmarshal(data, cfg); err != nil {
63+
return nil, err
64+
}
65+
return cfg, nil
6666
}
6767

6868
type config struct {

controllers/argocd/types_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ users:
6363
}}
6464
for _, tt := range tests {
6565
t.Run(tt.name, func(t *testing.T) {
66-
assert.Equalf(t, tt.want, parseKubeConfig(tt.args.data), "parseKubeConfig(%v)", tt.args.data)
66+
config, err := parseKubeConfig(tt.args.data)
67+
assert.Nil(t, err)
68+
assert.Equalf(t, tt.want, config, "parseKubeConfig(%v)", tt.args.data)
6769
})
6870
}
6971
}

0 commit comments

Comments
 (0)