Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit a6bb189

Browse files
committed
add mesh config upgrade during mesh upgrade
Signed-off-by: Thomas Stringer <[email protected]>
1 parent 8dccabb commit a6bb189

File tree

7 files changed

+571
-17
lines changed

7 files changed

+571
-17
lines changed

cmd/cli/mesh_upgrade.go

+17
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"helm.sh/helm/v3/pkg/chart"
1313
"helm.sh/helm/v3/pkg/chart/loader"
1414
"helm.sh/helm/v3/pkg/strvals"
15+
16+
"github.com/openservicemesh/osm/pkg/configupgrade"
1517
)
1618

1719
const upgradeDesc = `
@@ -112,6 +114,21 @@ func (u *meshUpgradeCmd) run(config *helm.Configuration) error {
112114
return err
113115
}
114116

117+
// Upgrade the MeshConfig in a way that is consistent with the new version.
118+
kubeConfig, err := settings.RESTClientGetter().ToRESTConfig()
119+
if err != nil {
120+
return err
121+
}
122+
meshConfigUpgrade := configupgrade.NewMeshConfigUpgrade(
123+
config,
124+
kubeConfig,
125+
settings.Namespace(),
126+
u.meshName,
127+
)
128+
if err := meshConfigUpgrade.Run(); err != nil {
129+
return err
130+
}
131+
115132
fmt.Fprintf(u.out, "OSM successfully upgraded mesh [%s] in namespace [%s]\n", u.meshName, settings.Namespace())
116133
return nil
117134
}

cmd/osm-bootstrap/osm-bootstrap.go

+6-12
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@ import (
4040
"github.com/openservicemesh/osm/pkg/version"
4141
)
4242

43-
const (
44-
meshConfigName = "osm-mesh-config"
45-
presetMeshConfigName = "preset-mesh-config"
46-
presetMeshConfigJSONKey = "preset-mesh-config.json"
47-
)
48-
4943
var (
5044
verbosity string
5145
osmNamespace string
@@ -146,7 +140,7 @@ func main() {
146140

147141
err = bootstrap.ensureMeshConfig()
148142
if err != nil {
149-
log.Fatal().Err(err).Msgf("Error setting up default MeshConfig %s from ConfigMap %s", meshConfigName, presetMeshConfigName)
143+
log.Fatal().Err(err).Msgf("Error setting up default MeshConfig %s from ConfigMap %s", constants.OSMMeshConfig, constants.PresetMeshConfig)
150144
return
151145
}
152146

@@ -213,7 +207,7 @@ func main() {
213207

214208
func (b *bootstrap) createDefaultMeshConfig() error {
215209
// find presets config map to build the default MeshConfig from that
216-
presetsConfigMap, err := b.kubeClient.CoreV1().ConfigMaps(b.namespace).Get(context.TODO(), presetMeshConfigName, metav1.GetOptions{})
210+
presetsConfigMap, err := b.kubeClient.CoreV1().ConfigMaps(b.namespace).Get(context.TODO(), constants.PresetMeshConfig, metav1.GetOptions{})
217211

218212
// If the presets MeshConfig could not be loaded return the error
219213
if err != nil {
@@ -223,7 +217,7 @@ func (b *bootstrap) createDefaultMeshConfig() error {
223217
// Create a default meshConfig
224218
defaultMeshConfig := buildDefaultMeshConfig(presetsConfigMap)
225219
if _, err := b.meshConfigClient.ConfigV1alpha1().MeshConfigs(b.namespace).Create(context.TODO(), defaultMeshConfig, metav1.CreateOptions{}); err == nil {
226-
log.Info().Msgf("MeshConfig (%s) created in namespace %s", meshConfigName, b.namespace)
220+
log.Info().Msgf("MeshConfig (%s) created in namespace %s", constants.OSMMeshConfig, b.namespace)
227221
return nil
228222
}
229223

@@ -236,7 +230,7 @@ func (b *bootstrap) createDefaultMeshConfig() error {
236230
}
237231

238232
func (b *bootstrap) ensureMeshConfig() error {
239-
_, err := b.meshConfigClient.ConfigV1alpha1().MeshConfigs(b.namespace).Get(context.TODO(), meshConfigName, metav1.GetOptions{})
233+
_, err := b.meshConfigClient.ConfigV1alpha1().MeshConfigs(b.namespace).Get(context.TODO(), constants.OSMMeshConfig, metav1.GetOptions{})
240234
if err == nil {
241235
return nil // default meshConfig was found
242236
}
@@ -302,7 +296,7 @@ func validateCLIParams() error {
302296
}
303297

304298
func buildDefaultMeshConfig(presetMeshConfigMap *corev1.ConfigMap) *v1alpha1.MeshConfig {
305-
presetMeshConfig := presetMeshConfigMap.Data[presetMeshConfigJSONKey]
299+
presetMeshConfig := presetMeshConfigMap.Data[constants.PresetMeshConfigJSONKey]
306300
presetMeshConfigSpec := v1alpha1.MeshConfigSpec{}
307301
err := json.Unmarshal([]byte(presetMeshConfig), &presetMeshConfigSpec)
308302
if err != nil {
@@ -315,7 +309,7 @@ func buildDefaultMeshConfig(presetMeshConfigMap *corev1.ConfigMap) *v1alpha1.Mes
315309
APIVersion: "config.openservicemesh.io/v1alpha1",
316310
},
317311
ObjectMeta: metav1.ObjectMeta{
318-
Name: meshConfigName,
312+
Name: constants.OSMMeshConfig,
319313
},
320314
Spec: presetMeshConfigSpec,
321315
}

cmd/osm-bootstrap/osm-bootstrap_test.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
fakeKube "k8s.io/client-go/kubernetes/fake"
1414

1515
"github.com/openservicemesh/osm/pkg/apis/config/v1alpha1"
16+
"github.com/openservicemesh/osm/pkg/constants"
1617
configClientset "github.com/openservicemesh/osm/pkg/gen/client/config/clientset/versioned"
1718
fakeConfig "github.com/openservicemesh/osm/pkg/gen/client/config/clientset/versioned/fake"
1819
)
@@ -22,7 +23,7 @@ var testNamespace = "test-namespace"
2223
var testMeshConfig *v1alpha1.MeshConfig = &v1alpha1.MeshConfig{
2324
ObjectMeta: metav1.ObjectMeta{
2425
Namespace: testNamespace,
25-
Name: meshConfigName,
26+
Name: constants.OSMMeshConfig,
2627
},
2728
Spec: v1alpha1.MeshConfigSpec{},
2829
}
@@ -33,11 +34,11 @@ var testPresetMeshConfigMap *corev1.ConfigMap = &corev1.ConfigMap{
3334
APIVersion: "v1",
3435
},
3536
ObjectMeta: metav1.ObjectMeta{
36-
Name: presetMeshConfigName,
37+
Name: constants.PresetMeshConfig,
3738
Namespace: testNamespace,
3839
},
3940
Data: map[string]string{
40-
presetMeshConfigJSONKey: `{
41+
constants.PresetMeshConfigJSONKey: `{
4142
"sidecar": {
4243
"enablePrivilegedInitContainer": false,
4344
"logLevel": "error",
@@ -82,7 +83,7 @@ func TestBuildDefaultMeshConfig(t *testing.T) {
8283
assert := tassert.New(t)
8384

8485
meshConfig := buildDefaultMeshConfig(testPresetMeshConfigMap)
85-
assert.Equal(meshConfig.Name, meshConfigName)
86+
assert.Equal(meshConfig.Name, constants.OSMMeshConfig)
8687
assert.Equal(meshConfig.Spec.Sidecar.LogLevel, "error")
8788
assert.Equal(meshConfig.Spec.Sidecar.ConfigResyncInterval, "2s")
8889
assert.False(meshConfig.Spec.Sidecar.EnablePrivilegedInitContainer)
@@ -200,7 +201,7 @@ func TestCreateDefaultMeshConfig(t *testing.T) {
200201
assert.Nil(err)
201202
}
202203

203-
_, err = b.meshConfigClient.ConfigV1alpha1().MeshConfigs(b.namespace).Get(context.TODO(), meshConfigName, metav1.GetOptions{})
204+
_, err = b.meshConfigClient.ConfigV1alpha1().MeshConfigs(b.namespace).Get(context.TODO(), constants.OSMMeshConfig, metav1.GetOptions{})
204205
if tc.expectDefaultMeshConfig {
205206
if err == nil {
206207
assert.Nil(err)

0 commit comments

Comments
 (0)