Skip to content

Commit 5017ee8

Browse files
committed
Refactor DeploymentState to DeploymentPhase
1 parent 14ee4f7 commit 5017ee8

File tree

8 files changed

+57
-69
lines changed

8 files changed

+57
-69
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2018 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 v1alpha
24+
25+
// DeploymentPhase is a strongly typed lifetime phase of a deployment
26+
type DeploymentPhase string
27+
28+
const (
29+
// DeploymentPhaseNone indicates that the phase is not set yet
30+
DeploymentPhaseNone DeploymentPhase = ""
31+
// DeploymentPhaseRunning indicates that the deployment is under control of the
32+
// ArangoDeployment operator.
33+
DeploymentPhaseRunning DeploymentPhase = "Running"
34+
// DeploymentPhaseFailed indicates that a deployment is in a failed state
35+
// from which automatic recovery is impossible. Inspect `Reason` for more info.
36+
DeploymentPhaseFailed DeploymentPhase = "Failed"
37+
)
38+
39+
// IsFailed returns true if given state is DeploymentStateFailed
40+
func (cs DeploymentPhase) IsFailed() bool {
41+
return cs == DeploymentPhaseFailed
42+
}

pkg/apis/deployment/v1alpha/deployment_state_test.go renamed to pkg/apis/deployment/v1alpha/deployment_phase_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@ import (
2828
"github.com/stretchr/testify/assert"
2929
)
3030

31-
func TestDeploymentStateIsFailed(t *testing.T) {
32-
assert.False(t, DeploymentStateNone.IsFailed())
33-
assert.False(t, DeploymentStateCreating.IsFailed())
34-
assert.True(t, DeploymentStateFailed.IsFailed())
35-
assert.False(t, DeploymentStateRunning.IsFailed())
36-
assert.False(t, DeploymentStateScaling.IsFailed())
37-
assert.False(t, DeploymentStateUpgrading.IsFailed())
31+
func TestDeploymentPhaseIsFailed(t *testing.T) {
32+
assert.False(t, DeploymentPhaseNone.IsFailed())
33+
assert.False(t, DeploymentPhaseCreating.IsFailed())
34+
assert.True(t, DeploymentPhaseFailed.IsFailed())
35+
assert.False(t, DeploymentPhaseRunning.IsFailed())
3836
}

pkg/apis/deployment/v1alpha/deployment_state.go

Lines changed: 0 additions & 47 deletions
This file was deleted.

pkg/apis/deployment/v1alpha/deployment_status.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ package v1alpha
2424

2525
// DeploymentStatus contains the status part of a Cluster resource.
2626
type DeploymentStatus struct {
27-
// State holds the current state of the deployment
28-
State DeploymentState `json:"state"`
27+
// Phase holds the current lifetime phase of the deployment
28+
Phase DeploymentPhase `json:"phase"`
2929
// Reason contains a human readable reason for reaching the current state (can be empty)
3030
Reason string `json:"reason,omitempty"` // Reason for current state
3131

pkg/deployment/cluster_scaling_integration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (ci *clusterScalingIntegration) ListenForClusterEvents(stopCh <-chan struct
7171
delay := time.Second * 2
7272

7373
// Is deployment in running state
74-
if ci.depl.status.State == api.DeploymentStateRunning {
74+
if ci.depl.status.Phase == api.DeploymentPhaseRunning {
7575
// Update cluster with our state
7676
ctx := context.Background()
7777
safeToAskCluster, err := ci.updateClusterServerCount(ctx)

pkg/deployment/deployment.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func (d *Deployment) send(ev *deploymentEvent) {
167167
func (d *Deployment) run() {
168168
log := d.deps.Log
169169

170-
if d.status.State == api.DeploymentStateNone {
170+
if d.status.Phase == api.DeploymentPhaseNone {
171171
// Create secrets
172172
if err := d.resources.EnsureSecrets(); err != nil {
173173
d.failOnError(err, "Failed to create secrets")
@@ -198,7 +198,7 @@ func (d *Deployment) run() {
198198
return
199199
}
200200

201-
d.status.State = api.DeploymentStateRunning
201+
d.status.Phase = api.DeploymentPhaseRunning
202202
if err := d.updateCRStatus(); err != nil {
203203
log.Warn().Err(err).Msg("update initial CR status failed")
204204
}
@@ -402,7 +402,7 @@ func (d *Deployment) reportFailedStatus() {
402402
log.Info().Msg("deployment failed. Reporting failed reason...")
403403

404404
op := func() error {
405-
d.status.State = api.DeploymentStateFailed
405+
d.status.Phase = api.DeploymentPhaseFailed
406406
err := d.updateCRStatus()
407407
if err == nil || k8sutil.IsNotFound(err) {
408408
// Status has been updated

pkg/deployment/resources/pod_inspector.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,9 @@ func (r *Resources) InspectPods() error {
142142
return nil
143143
})
144144

145-
// Check overall status update
146-
switch status.State {
147-
case api.DeploymentStateCreating:
148-
if status.Members.AllMembersReady() {
149-
status.State = api.DeploymentStateRunning
150-
}
151-
// TODO handle other State values
152-
}
145+
// Update overall conditions
146+
allMembersReady := status.Members.AllMembersReady()
147+
status.Conditions.Update(api.ConditionTypeReady, allMembersReady, "", "")
153148

154149
// Save status
155150
if err := r.context.UpdateStatus(status); err != nil {

pkg/operator/operator_deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (o *Operator) syncArangoDeployment(apiObject *api.ArangoDeployment) {
136136
func (o *Operator) handleDeploymentEvent(event *Event) error {
137137
apiObject := event.Deployment
138138

139-
if apiObject.Status.State.IsFailed() {
139+
if apiObject.Status.Phase.IsFailed() {
140140
deploymentsFailed.Inc()
141141
if event.Type == kwatch.Deleted {
142142
delete(o.deployments, apiObject.Name)

0 commit comments

Comments
 (0)