Skip to content

Commit ec9c8a6

Browse files
authored
[Bugfix] Fix backup flow (#636)
1 parent 858bbb5 commit ec9c8a6

File tree

12 files changed

+169
-17
lines changed

12 files changed

+169
-17
lines changed

pkg/apis/deployment/v1/image_info.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ func (l *ImageInfoList) AddOrUpdate(info ImageInfo) {
7474

7575
// Equal compares to ImageInfo
7676
func (i *ImageInfo) Equal(other *ImageInfo) bool {
77-
if i == nil || other == nil {
77+
if i == nil && other == nil {
78+
return true
79+
} else if i == nil || other == nil {
7880
return false
7981
} else if i == other {
8082
return true

pkg/apis/deployment/v1/member_status.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ type MemberStatus struct {
6767
ArangoVersion driver.Version `json:"arango-version,omitempty"`
6868
// ImageId holds the members ArangoDB image ID
6969
ImageID string `json:"image-id,omitempty"`
70+
// Image holds image details
71+
Image *ImageInfo `json:"image,omitempty"`
7072
}
7173

7274
// Equal checks for equality
@@ -81,7 +83,8 @@ func (s MemberStatus) Equal(other MemberStatus) bool {
8183
s.CleanoutJobID == other.CleanoutJobID &&
8284
reflect.DeepEqual(s.SideCarSpecs, other.SideCarSpecs) &&
8385
s.ArangoVersion == other.ArangoVersion &&
84-
s.ImageID == other.ImageID
86+
s.ImageID == other.ImageID &&
87+
s.Image.Equal(other.Image)
8588
}
8689

8790
// Age returns the duration since the creation timestamp of this member.

pkg/apis/deployment/v1/plan.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ const (
8181
ActionTypeUpdateTLSSNI ActionType = "UpdateTLSSNI"
8282
// ActionTypeSetCurrentImage causes status.CurrentImage to be updated to the image given in the action.
8383
ActionTypeSetCurrentImage ActionType = "SetCurrentImage"
84+
// ActionTypeSetCurrentImage replace image of member to current one.
85+
ActionTypeSetMemberCurrentImage ActionType = "SetMemberCurrentImage"
8486
// ActionTypeDisableClusterScaling turns off scaling DBservers and coordinators
8587
ActionTypeDisableClusterScaling ActionType = "ScalingDisabled"
8688
// ActionTypeEnableClusterScaling turns on scaling DBservers and coordinators

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

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

pkg/deployment/deployment_run_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ func runTestCase(t *testing.T, testCase testCaseStruct) {
152152
require.Equal(t, false, exist)
153153
_, exist = m.Conditions.Get(api.ConditionTypeAutoUpgrade)
154154
require.Equal(t, false, exist)
155+
156+
require.NotNil(t, m.Image)
157+
require.True(t, m.Image.Equal(d.apiObject.Status.CurrentImage))
155158
}
156159
return nil
157160
}

pkg/deployment/deployment_suite_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,13 @@ func (testCase *testCaseStruct) createTestPodData(deployment *Deployment, group
592592

593593
groupSpec := testCase.ArangoDeployment.Spec.GetServerGroupSpec(group)
594594
testCase.ExpectedPod.Spec.Tolerations = deployment.resources.CreatePodTolerations(group, groupSpec)
595+
596+
// Add image info
597+
if member, group, ok := deployment.apiObject.Status.Members.ElementByID(memberStatus.ID); ok {
598+
member.Image = deployment.apiObject.Status.CurrentImage
599+
600+
deployment.apiObject.Status.Members.Update(member, group)
601+
}
595602
}
596603

597604
func testCreateExporterContainerWithPortAndSecureEndpoint(secure, exporterSecure bool, resources core.ResourceRequirements, port uint16) core.Container {

pkg/deployment/members.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ func createMember(log zerolog.Logger, status *api.DeploymentStatus, group api.Se
9595
Phase: api.MemberPhaseNone,
9696
PersistentVolumeClaimName: k8sutil.CreatePersistentVolumeClaimName(deploymentName, role, id),
9797
PodName: "",
98+
Image: apiObject.Status.CurrentImage,
9899
}, group); err != nil {
99100
return "", maskAny(err)
100101
}
@@ -106,6 +107,7 @@ func createMember(log zerolog.Logger, status *api.DeploymentStatus, group api.Se
106107
Phase: api.MemberPhaseNone,
107108
PersistentVolumeClaimName: k8sutil.CreatePersistentVolumeClaimName(deploymentName, role, id),
108109
PodName: "",
110+
Image: apiObject.Status.CurrentImage,
109111
}, group); err != nil {
110112
return "", maskAny(err)
111113
}
@@ -117,6 +119,7 @@ func createMember(log zerolog.Logger, status *api.DeploymentStatus, group api.Se
117119
Phase: api.MemberPhaseNone,
118120
PersistentVolumeClaimName: k8sutil.CreatePersistentVolumeClaimName(deploymentName, role, id),
119121
PodName: "",
122+
Image: apiObject.Status.CurrentImage,
120123
}, group); err != nil {
121124
return "", maskAny(err)
122125
}
@@ -128,6 +131,7 @@ func createMember(log zerolog.Logger, status *api.DeploymentStatus, group api.Se
128131
Phase: api.MemberPhaseNone,
129132
PersistentVolumeClaimName: "",
130133
PodName: "",
134+
Image: apiObject.Status.CurrentImage,
131135
}, group); err != nil {
132136
return "", maskAny(err)
133137
}
@@ -139,6 +143,7 @@ func createMember(log zerolog.Logger, status *api.DeploymentStatus, group api.Se
139143
Phase: api.MemberPhaseNone,
140144
PersistentVolumeClaimName: "",
141145
PodName: "",
146+
Image: apiObject.Status.CurrentImage,
142147
}, group); err != nil {
143148
return "", maskAny(err)
144149
}
@@ -150,6 +155,7 @@ func createMember(log zerolog.Logger, status *api.DeploymentStatus, group api.Se
150155
Phase: api.MemberPhaseNone,
151156
PersistentVolumeClaimName: "",
152157
PodName: "",
158+
Image: apiObject.Status.CurrentImage,
153159
}, group); err != nil {
154160
return "", maskAny(err)
155161
}

pkg/deployment/reconcile/action_context.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,13 @@ func (ac *actionContext) GetCurrentImageInfo() (api.ImageInfo, bool) {
399399
// SetCurrentImage changes the CurrentImage field in the deployment
400400
// status to the given image.
401401
func (ac *actionContext) SetCurrentImage(imageInfo api.ImageInfo) error {
402-
status, lastVersion := ac.context.GetStatus()
403-
status.CurrentImage = &imageInfo
404-
if err := ac.context.UpdateStatus(status, lastVersion); err != nil {
405-
return maskAny(err)
406-
}
407-
return nil
402+
return ac.context.WithStatusUpdate(func(s *api.DeploymentStatus) bool {
403+
if s.CurrentImage == nil || s.CurrentImage.Image != imageInfo.Image {
404+
s.CurrentImage = &imageInfo
405+
return true
406+
}
407+
return false
408+
}, true)
408409
}
409410

410411
// InvalidateSyncStatus resets the sync state to false and triggers an inspection
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2020 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+
// Author Ewout Prangsma
21+
//
22+
23+
package reconcile
24+
25+
import (
26+
"context"
27+
28+
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
29+
"github.com/rs/zerolog"
30+
)
31+
32+
func init() {
33+
registerAction(api.ActionTypeSetMemberCurrentImage, newSetCurrentMemberImageAction)
34+
}
35+
36+
// newSetCurrentImageAction creates a new Action that implements the given
37+
// planned SetCurrentImage action.
38+
func newSetCurrentMemberImageAction(log zerolog.Logger, action api.Action, actionCtx ActionContext) Action {
39+
a := &setCurrentMemberImageAction{}
40+
41+
a.actionImpl = newActionImplDefRef(log, action, actionCtx, upgradeMemberTimeout)
42+
43+
return a
44+
}
45+
46+
// setCurrentImageAction implements an SetCurrentImage.
47+
type setCurrentMemberImageAction struct {
48+
// actionImpl implement timeout and member id functions
49+
actionImpl
50+
}
51+
52+
// Start performs the start of the action.
53+
// Returns true if the action is completely finished, false in case
54+
// the start time needs to be recorded and a ready condition needs to be checked.
55+
func (a *setCurrentMemberImageAction) Start(ctx context.Context) (bool, error) {
56+
ready, _, err := a.CheckProgress(ctx)
57+
if err != nil {
58+
return false, maskAny(err)
59+
}
60+
return ready, nil
61+
}
62+
63+
// CheckProgress checks the progress of the action.
64+
// Returns true if the action is completely finished, false otherwise.
65+
func (a *setCurrentMemberImageAction) CheckProgress(ctx context.Context) (bool, bool, error) {
66+
log := a.log
67+
68+
imageInfo, found := a.actionCtx.GetImageInfo(a.action.Image)
69+
if !found {
70+
log.Info().Msgf("Image not found")
71+
return true, false, nil
72+
}
73+
74+
if err := a.actionCtx.WithStatusUpdate(func(s *api.DeploymentStatus) bool {
75+
m, g, found := s.Members.ElementByID(a.action.MemberID)
76+
if !found {
77+
log.Error().Msg("No such member")
78+
return false
79+
}
80+
81+
m.Image = &imageInfo
82+
83+
if err := s.Members.Update(m, g); err != nil {
84+
log.Error().Msg("Member update failed")
85+
return false
86+
}
87+
88+
return true
89+
}); err != nil {
90+
log.Error().Msg("Member failed")
91+
return true, false, nil
92+
}
93+
94+
return true, false, nil
95+
}

pkg/deployment/reconcile/action_upgrade_current_image.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ func (a *setCurrentImageAction) CheckProgress(ctx context.Context) (bool, bool,
7272
if err := a.actionCtx.SetCurrentImage(imageInfo); err != nil {
7373
return false, false, maskAny(err)
7474
}
75-
log.Info().Str("image", a.action.Image).Msg("Changed current image")
75+
log.Info().Str("image", a.action.Image).Str("to", imageInfo.Image).Msg("Changed current main image")
7676
return true, false, nil
7777
}

0 commit comments

Comments
 (0)