Skip to content

Commit

Permalink
Fix nil in log (#1035)
Browse files Browse the repository at this point in the history
  • Loading branch information
chilianyi authored Feb 28, 2024
1 parent f0a23fe commit 1b26e3f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion controllers/argocd/multi-cluster-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func getArgoClusterConfigObject(configText string) (object *ClusterConfig) {
rawDecodedconfig, _ := base64.StdEncoding.DecodeString(configText)

var kubeconfig *config
if kubeconfig = parseKubeConfig(rawDecodedconfig); kubeconfig == nil {
if kubeconfig, _ = parseKubeConfig(rawDecodedconfig); kubeconfig == nil {
return
}

Expand Down
12 changes: 6 additions & 6 deletions controllers/argocd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ limitations under the License.
package argocd

import (
"fmt"
"gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -58,11 +57,12 @@ type TLSClientConfig struct {
CAData []byte `json:"caData,omitempty"`
}

func parseKubeConfig(data []byte) (cfg *config) {
cfg = &config{}
err := yaml.Unmarshal(data, cfg)
fmt.Println(err)
return
func parseKubeConfig(data []byte) (*config, error) {
cfg := &config{}
if err := yaml.Unmarshal(data, cfg); err != nil {
return nil, err
}
return cfg, nil
}

type config struct {
Expand Down
4 changes: 3 additions & 1 deletion controllers/argocd/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ users:
}}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equalf(t, tt.want, parseKubeConfig(tt.args.data), "parseKubeConfig(%v)", tt.args.data)
config, err := parseKubeConfig(tt.args.data)
assert.Nil(t, err)
assert.Equalf(t, tt.want, config, "parseKubeConfig(%v)", tt.args.data)
})
}
}

0 comments on commit 1b26e3f

Please sign in to comment.