Skip to content

Commit ac35fd7

Browse files
authored
[Feature] Add upgrade steps procedure (#933)
1 parent 279c053 commit ac35fd7

17 files changed

+1045
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- (Bugfix) Fix NPE in State fetcher
1414
- (Refactor) Configurable throttle inspector
1515
- (Bugfix) Skip Replace operation on DBServer if they need to be scaled down
16+
- (Feature) Upgrade procedure steps
1617

1718
## [1.2.8](https://github.com/arangodb/kube-arangodb/tree/1.2.8) (2022-02-24)
1819
- Do not check License V2 on Community images

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ set-api-version/%:
477477
"$(ROOT)/pkg/util/" \
478478
"$(ROOT)/pkg/handlers/" \
479479
"$(ROOT)/pkg/apis/backup/" \
480+
"$(ROOT)/pkg/upgrade/" \
480481
| cut -d ':' -f 1 | sort | uniq \
481482
| xargs -n 1 sed -i "s#github.com/arangodb/kube-arangodb/pkg/apis/$*/v[A-Za-z0-9]\+#github.com/arangodb/kube-arangodb/pkg/apis/$*/v$(API_VERSION)#g"
482483
@grep -rHn "DatabaseV[A-Za-z0-9]\+()" \
@@ -487,6 +488,7 @@ set-api-version/%:
487488
"$(ROOT)/pkg/util/" \
488489
"$(ROOT)/pkg/handlers/" \
489490
"$(ROOT)/pkg/apis/backup/" \
491+
"$(ROOT)/pkg/upgrade/" \
490492
| cut -d ':' -f 1 | sort | uniq \
491493
| xargs -n 1 sed -i "s#DatabaseV[A-Za-z0-9]\+()\.#DatabaseV$(API_VERSION)().#g"
492494
@grep -rHn "ReplicationV[A-Za-z0-9]\+()" \
@@ -497,6 +499,7 @@ set-api-version/%:
497499
"$(ROOT)/pkg/util/" \
498500
"$(ROOT)/pkg/handlers" \
499501
"$(ROOT)/pkg/apis/backup/" \
502+
"$(ROOT)/pkg/upgrade/" \
500503
| cut -d ':' -f 1 | sort | uniq \
501504
| xargs -n 1 sed -i "s#ReplicationV[A-Za-z0-9]\+()\.#ReplicationV$(API_VERSION)().#g"
502505

pkg/apis/deployment/v1/deployment_status.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ type DeploymentStatus struct {
8585
Rebalancer *ArangoDeploymentRebalancerStatus `json:"rebalancer,omitempty"`
8686

8787
BackOff BackOff `json:"backoff,omitempty"`
88+
89+
Version *Version `json:"version,omitempty"`
8890
}
8991

9092
// Equal checks for equality
@@ -105,7 +107,8 @@ func (ds *DeploymentStatus) Equal(other DeploymentStatus) bool {
105107
ds.SecretHashes.Equal(other.SecretHashes) &&
106108
ds.Agency.Equal(other.Agency) &&
107109
ds.Topology.Equal(other.Topology) &&
108-
ds.BackOff.Equal(other.BackOff)
110+
ds.BackOff.Equal(other.BackOff) &&
111+
ds.Version.Equal(other.Version)
109112
}
110113

111114
// IsForceReload returns true if ForceStatusReload is set to true

pkg/apis/deployment/v1/version.go

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package v1
22+
23+
import (
24+
"encoding/json"
25+
"fmt"
26+
"strconv"
27+
"strings"
28+
29+
"github.com/pkg/errors"
30+
)
31+
32+
var _ json.Marshaler = Version{}
33+
var _ json.Unmarshaler = &Version{}
34+
35+
type Version struct {
36+
Major int `json:"major"`
37+
Minor int `json:"minor"`
38+
Patch int `json:"patch"`
39+
ID int `json:"ID,omitempty"`
40+
}
41+
42+
func (v Version) Compare(b Version) int {
43+
if v.Major > b.Major {
44+
return 1
45+
} else if v.Major < b.Major {
46+
return -1
47+
}
48+
49+
if v.Minor > b.Minor {
50+
return 1
51+
} else if v.Minor < b.Minor {
52+
return -1
53+
}
54+
55+
if v.Patch > b.Patch {
56+
return 1
57+
} else if v.Patch < b.Patch {
58+
return -1
59+
}
60+
61+
if v.ID < b.ID {
62+
return 1
63+
} else if b.ID < v.ID {
64+
return -1
65+
}
66+
67+
return 0
68+
}
69+
70+
func (v *Version) Equal(b *Version) bool {
71+
if v == nil && b == nil {
72+
return true
73+
}
74+
if v == nil || b == nil {
75+
return true
76+
}
77+
return v.Major == b.Major && v.Minor == b.Minor && v.Patch == b.Patch && v.ID == b.ID
78+
}
79+
80+
func (v *Version) UnmarshalJSON(bytes []byte) error {
81+
if v == nil {
82+
return errors.Errorf("Nil version provided")
83+
}
84+
85+
var s string
86+
87+
if err := json.Unmarshal(bytes, &s); err != nil {
88+
*v = Version{
89+
Major: 0,
90+
Minor: 0,
91+
Patch: 0,
92+
}
93+
return nil
94+
}
95+
96+
z := strings.Split(s, ".")
97+
98+
i := make([]int, len(z))
99+
100+
for id, z := range z {
101+
if q, err := strconv.Atoi(z); err != nil {
102+
*v = Version{
103+
Major: 0,
104+
Minor: 0,
105+
Patch: 0,
106+
}
107+
return nil
108+
} else {
109+
i[id] = q
110+
}
111+
}
112+
switch l := len(i); l {
113+
case 1:
114+
var n Version
115+
116+
n.Major = i[0]
117+
118+
*v = n
119+
case 2:
120+
var n Version
121+
122+
n.Major = i[0]
123+
n.Minor = i[1]
124+
125+
*v = n
126+
case 3:
127+
var n Version
128+
129+
n.Major = i[0]
130+
n.Minor = i[1]
131+
n.Patch = i[2]
132+
133+
*v = n
134+
case 4:
135+
var n Version
136+
137+
n.Major = i[0]
138+
n.Minor = i[1]
139+
n.Patch = i[2]
140+
n.ID = i[3]
141+
142+
*v = n
143+
default:
144+
*v = Version{
145+
Major: 0,
146+
Minor: 0,
147+
Patch: 0,
148+
}
149+
return nil
150+
}
151+
152+
return nil
153+
}
154+
155+
func (v Version) MarshalJSON() ([]byte, error) {
156+
if v.ID == 0 {
157+
return json.Marshal(fmt.Sprintf("%d.%d.%d", v.Major, v.Minor, v.Patch))
158+
}
159+
160+
return json.Marshal(fmt.Sprintf("%d.%d.%d.%d", v.Major, v.Minor, v.Patch, v.ID))
161+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2016-2022 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package v1
22+
23+
import (
24+
"encoding/json"
25+
"testing"
26+
27+
"github.com/stretchr/testify/require"
28+
)
29+
30+
func remarshalVersionWithExpected(t *testing.T, version, expected string) {
31+
t.Run(version, func(t *testing.T) {
32+
var v Version
33+
34+
data, err := json.Marshal(version)
35+
require.NoError(t, err)
36+
37+
require.NoError(t, json.Unmarshal(data, &v))
38+
39+
data, err = json.Marshal(v)
40+
require.NoError(t, err)
41+
42+
var newV string
43+
44+
require.NoError(t, json.Unmarshal(data, &newV))
45+
46+
require.Equal(t, expected, newV)
47+
})
48+
}
49+
50+
func Test_Version(t *testing.T) {
51+
remarshalVersionWithExpected(t, "1", "1.0.0")
52+
remarshalVersionWithExpected(t, "1.0", "1.0.0")
53+
remarshalVersionWithExpected(t, "1.0.0", "1.0.0")
54+
remarshalVersionWithExpected(t, "1.0.0.0", "1.0.0")
55+
remarshalVersionWithExpected(t, "1.0.0.1", "1.0.0.1")
56+
remarshalVersionWithExpected(t, "Invalid", "0.0.0")
57+
}

pkg/apis/deployment/v1/zz_generated.deepcopy.go

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/deployment/v2alpha1/deployment_status.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ type DeploymentStatus struct {
8585
Rebalancer *ArangoDeploymentRebalancerStatus `json:"rebalancer,omitempty"`
8686

8787
BackOff BackOff `json:"backoff,omitempty"`
88+
89+
Version *Version `json:"version,omitempty"`
8890
}
8991

9092
// Equal checks for equality
@@ -105,7 +107,8 @@ func (ds *DeploymentStatus) Equal(other DeploymentStatus) bool {
105107
ds.SecretHashes.Equal(other.SecretHashes) &&
106108
ds.Agency.Equal(other.Agency) &&
107109
ds.Topology.Equal(other.Topology) &&
108-
ds.BackOff.Equal(other.BackOff)
110+
ds.BackOff.Equal(other.BackOff) &&
111+
ds.Version.Equal(other.Version)
109112
}
110113

111114
// IsForceReload returns true if ForceStatusReload is set to true

0 commit comments

Comments
 (0)