Skip to content

Commit c22ea03

Browse files
committed
fixes
Signed-off-by: kumarabd <[email protected]>
1 parent 968be52 commit c22ea03

File tree

8 files changed

+34
-39
lines changed

8 files changed

+34
-39
lines changed

internal/config/config.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package config
44
type Handler interface {
55

66
// SetKey sets a key value in the config
7-
SetKey(key string, value string)
7+
SetKey(key string, value string) error
88

99
// GetKey gets a key value from the config
1010
GetKey(key string) (string, error)
@@ -13,10 +13,7 @@ type Handler interface {
1313
Server(result interface{}) error
1414

1515
// MeshSpec provides the mesh specific configuration
16-
MeshSpec(result interface{}) error
17-
18-
// MeshInstance provides the mesh specific configuration
19-
MeshInstance(result interface{}) error
16+
Mesh(result interface{}) error
2017

2118
// Operations provides the list of operations available
2219
Operations(result interface{}) error

internal/config/keys.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const (
44
local = "local" // local is the key for local config
55

66
// Operation keys
7-
InstallNginxLatest = "install-nginx-0.6.0" // InstallKuma is the key to install kuma
7+
InstallNginxLatest = "install-nginx-060" // InstallNginxLatest is the key to install nginx
88

99
InstallSampleBookInfo = "install-sample-bookinfo" // InstallSampleBookInfo is the key to install sample bookinfo application
1010

internal/config/local.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ func NewLocal() (Handler, error) {
2222
// -------------------------------------------Application config methods----------------------------------------------------------------
2323

2424
// SetKey sets a key value in local store
25-
func (l *Local) SetKey(key string, value string) {
25+
func (l *Local) SetKey(key string, value string) error {
2626
l.store[key] = value
27+
return nil
2728
}
2829

2930
// GetKey gets a key value from local store
@@ -47,7 +48,7 @@ func (l *Local) Server(result interface{}) error {
4748
}
4849

4950
// MeshSpec provides mesh specific configuration
50-
func (l *Local) MeshSpec(result interface{}) error {
51+
func (l *Local) Mesh(result interface{}) error {
5152
d := `{
5253
"name": "Nginx Service Mesh",
5354
"status": "not installed",
@@ -56,18 +57,6 @@ func (l *Local) MeshSpec(result interface{}) error {
5657
return utils.Unmarshal(d, result)
5758
}
5859

59-
// MeshInstance provides mesh specific configuration
60-
func (l *Local) MeshInstance(result interface{}) error {
61-
d := `{
62-
"installmode": "flat",
63-
"installplatform": "kubernetes",
64-
"installzone": " ",
65-
"mgmtaddr": "0.0.0.0:8000",
66-
"nginxaddr": "5681"
67-
}`
68-
return utils.Unmarshal(d, result)
69-
}
70-
7160
// Operations provides operations in the mesh
7261
func (l *Local) Operations(result interface{}) error {
7362
d, err := utils.Marshal(operations)

internal/config/viper.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ func NewViper() (Handler, error) {
2323

2424
v.SetDefault("server", server)
2525
v.SetDefault("mesh", mesh)
26+
v.SetDefault("operations", operations)
27+
2628
err := v.WriteConfig()
2729
if err != nil {
2830
_, er := os.Create(fmt.Sprintf("%s/%s", filepath, filename))
@@ -37,9 +39,13 @@ func NewViper() (Handler, error) {
3739
}
3840

3941
// SetKey sets a key value in viper
40-
func (v *Viper) SetKey(key string, value string) {
42+
func (v *Viper) SetKey(key string, value string) error {
4143
v.instance.Set(key, value)
42-
_ = v.instance.WriteConfig()
44+
err := v.instance.WriteConfig()
45+
if err != nil {
46+
return ErrViper(err)
47+
}
48+
return nil
4349
}
4450

4551
// GetKey gets a key value from viper
@@ -68,28 +74,21 @@ func (v *Viper) Server(result interface{}) error {
6874
}
6975

7076
// MeshSpec provides mesh specific configuration
71-
func (v *Viper) MeshSpec(result interface{}) error {
72-
err := v.instance.ReadInConfig()
77+
func (v *Viper) Mesh(result interface{}) error {
78+
s, err := v.GetKey("mesh")
7379
if err != nil {
7480
return ErrViper(err)
7581
}
76-
return v.instance.Unmarshal(&result)
77-
}
7882

79-
// MeshInstance provides mesh specific configuration
80-
func (v *Viper) MeshInstance(result interface{}) error {
81-
err := v.instance.ReadInConfig()
82-
if err != nil {
83-
return ErrViper(err)
84-
}
85-
return v.instance.Unmarshal(&result)
83+
return utils.Unmarshal(s, &result)
8684
}
8785

8886
// Operations provides list of operations available
8987
func (v *Viper) Operations(result interface{}) error {
90-
err := v.instance.ReadInConfig()
88+
s, err := v.GetKey("operations")
9189
if err != nil {
9290
return ErrViper(err)
9391
}
94-
return v.instance.Unmarshal(&result)
92+
93+
return utils.Unmarshal(s, &result)
9594
}

main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ func main() {
3838
}
3939
service := &grpc.Service{}
4040
_ = cfg.Server(&service)
41-
cfg.SetKey("kube-config-path", kubeConfigPath)
41+
err = cfg.SetKey("kube-config-path", kubeConfigPath)
42+
if err != nil {
43+
log.Err("Cannot set kubeconfig path", err.Error())
44+
os.Exit(1)
45+
}
4246

4347
// // Initialize Tracing instance
4448
// tracer, err := tracing.New(service.Name, service.TraceURL)

nginx/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (h *handler) installNginx(del bool, version string) (string, error) {
2727
meshinstance := &MeshInstance{
2828
InstallVersion: version,
2929
}
30-
err := h.config.MeshInstance(meshinstance)
30+
err := h.config.Mesh(meshinstance)
3131
if err != nil {
3232
return status, ErrMeshConfig(err)
3333
}

nginx/operations.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ func (h *handler) ApplyOperation(ctx context.Context, op string, id string, del
4141
hh.StreamErr(e, err)
4242
return
4343
}
44-
h.config.SetKey(cfg.RunningMeshVersion, operations[op].Properties["version"])
44+
err = h.config.SetKey(cfg.RunningMeshVersion, operations[op].Properties["version"])
45+
if err != nil {
46+
e.Summary = fmt.Sprintf("Error while %s Nginx service mesh", status)
47+
e.Details = err.Error()
48+
hh.StreamErr(e, err)
49+
return
50+
}
4551
ee.Summary = fmt.Sprintf("Nginx service mesh %s successfully", status)
4652
ee.Details = fmt.Sprintf("The Nginx service mesh is now %s.", status)
4753
hh.StreamInfo(e)

nginx/spec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type Spec struct {
1010
// GetName returns the name of the mesh
1111
func (h *handler) GetName() string {
1212
spec := &Spec{}
13-
err := h.config.MeshSpec(&spec)
13+
err := h.config.Mesh(&spec)
1414
if err != nil {
1515
h.log.Err("1000", err.Error())
1616
return "Not set"

0 commit comments

Comments
 (0)