-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathsite_config_update.go
64 lines (60 loc) · 1.78 KB
/
site_config_update.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package client
import (
"context"
"github.com/skupperproject/skupper/pkg/qdr"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/skupperproject/skupper/api/types"
)
func (cli *VanClient) SiteConfigUpdate(ctx context.Context, config types.SiteConfigSpec) ([]string, error) {
configmap, err := cli.KubeClient.CoreV1().ConfigMaps(cli.Namespace).Get(ctx, types.SiteConfigMapName, metav1.GetOptions{})
if err != nil {
return nil, err
}
// For now, only update router-logging and/or router-debug-mode (TODO: update of other options)
latestLogging := qdr.RouterLogConfigToString(config.Router.Logging)
updateLogging := false
if configmap.Data[SiteConfigRouterLoggingKey] != latestLogging {
configmap.Data[SiteConfigRouterLoggingKey] = latestLogging
updateLogging = true
}
updateDebugMode := false
if configmap.Data[SiteConfigRouterDebugModeKey] != config.Router.DebugMode {
configmap.Data[SiteConfigRouterDebugModeKey] = config.Router.DebugMode
updateDebugMode = true
}
if updateLogging || updateDebugMode {
configmap, err = cli.KubeClient.CoreV1().ConfigMaps(cli.Namespace).Update(ctx, configmap, metav1.UpdateOptions{})
if err != nil {
return nil, err
}
}
updates := []string{}
if updateLogging {
updated, err := cli.RouterUpdateLogging(ctx, configmap, !updateDebugMode)
if errors.IsNotFound(err) {
return nil, nil
}
if err != nil {
return nil, err
}
if !updated {
return nil, nil
}
updates = append(updates, "router logging")
}
if updateDebugMode {
updated, err := cli.RouterUpdateDebugMode(ctx, configmap)
if errors.IsNotFound(err) {
return nil, nil
}
if err != nil {
return nil, err
}
if !updated {
return nil, nil
}
updates = append(updates, "router debug mode")
}
return updates, nil
}