-
Notifications
You must be signed in to change notification settings - Fork 260
/
upgrade.go
110 lines (91 loc) · 3.42 KB
/
upgrade.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
Copyright The CloudNativePG Contributors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package utils
import (
"fmt"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
apiv1 "github.com/cloudnative-pg/cloudnative-pg/api/v1"
. "github.com/onsi/ginkgo/v2" // nolint
. "github.com/onsi/gomega" // nolint
)
// CreateOperatorConfigurationMap creates the operator namespace and enables/disable the online upgrade for
// the instance manager
func CreateOperatorConfigurationMap(pgOperatorNamespace, configName string, isOnline bool, env *TestingEnvironment) {
By("creating operator namespace", func() {
// Create a upgradeNamespace for all the resources
namespacedName := types.NamespacedName{
Name: pgOperatorNamespace,
}
namespaceResource := &corev1.Namespace{}
err := env.Client.Get(env.Ctx, namespacedName, namespaceResource)
if apierrors.IsNotFound(err) {
err = env.CreateNamespace(pgOperatorNamespace)
Expect(err).ToNot(HaveOccurred())
} else if err != nil {
Expect(err).ToNot(HaveOccurred())
}
})
By(fmt.Sprintf("ensuring 'ENABLE_INSTANCE_MANAGER_INPLACE_UPDATES' is set to %v", isOnline), func() {
enable := "false"
if isOnline {
enable = "true"
}
configMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Namespace: pgOperatorNamespace,
Name: configName,
},
Data: map[string]string{"ENABLE_INSTANCE_MANAGER_INPLACE_UPDATES": enable},
}
_, err := CreateObject(env, configMap)
Expect(err).NotTo(HaveOccurred())
})
}
// InstallLatestCNPGOperator installs an operator version with the most recent release tag
func InstallLatestCNPGOperator(releaseTag string, env *TestingEnvironment) {
mostRecentReleasePath := "../../releases/cnpg-" + releaseTag + ".yaml"
Eventually(func() error {
GinkgoWriter.Printf("installing: %s\n", mostRecentReleasePath)
_, stderr, err := RunUnchecked("kubectl apply --server-side --force-conflicts -f " + mostRecentReleasePath)
if err != nil {
GinkgoWriter.Printf("stderr: %s\n", stderr)
}
return err
}, 60).ShouldNot(HaveOccurred())
Eventually(func() error {
_, _, err := RunUnchecked(
"kubectl wait --for condition=established --timeout=60s " +
"crd/clusters.postgresql.cnpg.io")
return err
}, 150).ShouldNot(HaveOccurred())
Eventually(func() error {
mapping, err := env.Client.RESTMapper().RESTMapping(
schema.GroupKind{Group: apiv1.GroupVersion.Group, Kind: apiv1.ClusterKind},
apiv1.GroupVersion.Version)
if err != nil {
return err
}
GinkgoWriter.Printf("found mapping REST endpoint: %s\n", mapping.GroupVersionKind.String())
return nil
}, 150).ShouldNot(HaveOccurred())
Eventually(func() error {
_, _, err := RunUnchecked(
"kubectl wait --for=condition=Available --timeout=2m -n cnpg-system " +
"deployments cnpg-controller-manager")
return err
}, 150).ShouldNot(HaveOccurred())
}