Skip to content

Commit

Permalink
🍱 [minor] Add NoDowntimeGuarantee flag (#140)
Browse files Browse the repository at this point in the history
* feat: add customMessage field to s2h workflow

* fix: reporter send with criteria and add test case

* fix: change customMessage to extraMessage

* example: add extraMessage to example config.yaml

* fix: clean-up slackExtraMessage

* chore: extraMessage example config descption

* fix: refactor and change description

* chore: clean-up unused parse string

* chore: edit example extraMessage description

* fix: slack reporter_test unused parse string

* feat: add switch before demote flag

* fix: change to NoDowntimeGuarantee, add logging and logic to send the report

* fix: send the report only active namespace has been promoted

* chore: edit a warning description

* fix: add condition to check noDowntime cannot be nil

* chore: edit description of the examples
  • Loading branch information
mmengspv authored Oct 21, 2022
1 parent a970348 commit 9065397
Show file tree
Hide file tree
Showing 21 changed files with 157 additions and 10 deletions.
4 changes: 4 additions & 0 deletions api/v1/activepromotion_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ type ActivePromotionSpec struct {
// PromotedBy represents a person who promoted the ActivePromotion
// +optional
PromotedBy string `json:"promotedBy,omitempty"`

// NoDowntimeGuarantee represents a flag for switching to the new namespace before demoting the active namespace and guarantees the process will not have a downtime
// +optional
NoDowntimeGuarantee *bool `json:"noDowntimeGuarantee,omitempty"`
}

func (s *ActivePromotionSpec) SetTearDownDuration(d metav1.Duration) {
Expand Down
3 changes: 3 additions & 0 deletions api/v1/config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ type ConfigActivePromotion struct {
// +optional
OutdatedNotification *OutdatedNotification `json:"outdatedNotification,omitempty"`

// NoDowntimeGuarantee defines a flag for switching to the new namespace before demoting the active namespace and guarantees the process will not have a downtime
NoDowntimeGuarantee bool `json:"noDowntimeGuarantee,omitempty"`

// Deployment represents configuration about deploy
// +optional
Deployment *ConfigDeploy `json:"deployment,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions config/crds/env.samsahai.io_activepromotionhistories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ spec:
description: ActivePromotionSpec defines the desired state of
ActivePromotion
properties:
noDowntimeGuarantee:
description: NoDowntimeGuarantee represents a flag for switching
to the new namespace before demoting the active namespace
and guarantees the process will not have a downtime
type: boolean
noOfRetry:
description: NoOfRetry represents how many times this active
promotion process has been run
Expand Down
5 changes: 5 additions & 0 deletions config/crds/env.samsahai.io_activepromotions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ spec:
spec:
description: ActivePromotionSpec defines the desired state of ActivePromotion
properties:
noDowntimeGuarantee:
description: NoDowntimeGuarantee represents a flag for switching to
the new namespace before demoting the active namespace and guarantees
the process will not have a downtime
type: boolean
noOfRetry:
description: NoOfRetry represents how many times this active promotion
process has been run
Expand Down
10 changes: 10 additions & 0 deletions config/crds/env.samsahai.io_configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ spec:
description: MaxRetry defines max retry counts of active promotion
process in case failure
type: integer
noDowntimeGuarantee:
description: NoDowntimeGuarantee defines a flag for switching
to the new namespace before demoting the active namespace and
guarantees the process will not have a downtime
type: boolean
outdatedNotification:
description: OutdatedNotification defines a configuration of outdated
notification
Expand Down Expand Up @@ -1034,6 +1039,11 @@ spec:
description: MaxRetry defines max retry counts of active promotion
process in case failure
type: integer
noDowntimeGuarantee:
description: NoDowntimeGuarantee defines a flag for switching
to the new namespace before demoting the active namespace
and guarantees the process will not have a downtime
type: boolean
outdatedNotification:
description: OutdatedNotification defines a configuration
of outdated notification
Expand Down
10 changes: 9 additions & 1 deletion docs/docs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at
// 2022-08-05 12:18:44.527278 +0700 +07 m=+0.172559437
// 2022-10-19 11:09:44.83837 +0700 +07 m=+0.333853050

package docs

Expand Down Expand Up @@ -954,6 +954,10 @@ var doc = `{
"v1.ActivePromotionSpec": {
"type": "object",
"properties": {
"noDowntimeGuarantee": {
"description": "NoDowntimeGuarantee represents a flag for switching to the new namespace before demoting the active namespace and guarantees the process will not have a downtime\n+optional",
"type": "boolean"
},
"noOfRetry": {
"description": "NoOfRetry represents how many times this active promotion process has been run\n+optional",
"type": "integer"
Expand Down Expand Up @@ -1167,6 +1171,10 @@ var doc = `{
"description": "MaxRetry defines max retry counts of active promotion process in case failure\n+optional",
"type": "integer"
},
"noDowntimeGuarantee": {
"description": "NoDowntimeGuarantee defines a flag for switching to the new namespace before demoting the active namespace and guarantees the process will not have a downtime",
"type": "boolean"
},
"outdatedNotification": {
"description": "OutdatedNotification defines a configuration of outdated notification\n+optional",
"type": "object",
Expand Down
8 changes: 8 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,10 @@
"v1.ActivePromotionSpec": {
"type": "object",
"properties": {
"noDowntimeGuarantee": {
"description": "NoDowntimeGuarantee represents a flag for switching to the new namespace before demoting the active namespace and guarantees the process will not have a downtime\n+optional",
"type": "boolean"
},
"noOfRetry": {
"description": "NoOfRetry represents how many times this active promotion process has been run\n+optional",
"type": "integer"
Expand Down Expand Up @@ -1146,6 +1150,10 @@
"description": "MaxRetry defines max retry counts of active promotion process in case failure\n+optional",
"type": "integer"
},
"noDowntimeGuarantee": {
"description": "NoDowntimeGuarantee defines a flag for switching to the new namespace before demoting the active namespace and guarantees the process will not have a downtime",
"type": "boolean"
},
"outdatedNotification": {
"description": "OutdatedNotification defines a configuration of outdated notification\n+optional",
"type": "object",
Expand Down
10 changes: 10 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ definitions:
type: object
v1.ActivePromotionSpec:
properties:
noDowntimeGuarantee:
description: |-
NoDowntimeGuarantee represents a flag for switching to the new namespace before demoting the active namespace and guarantees the process will not have a downtime
+optional
type: boolean
noOfRetry:
description: |-
NoOfRetry represents how many times this active promotion process has been run
Expand Down Expand Up @@ -258,6 +263,11 @@ definitions:
MaxRetry defines max retry counts of active promotion process in case failure
+optional
type: integer
noDowntimeGuarantee:
description: NoDowntimeGuarantee defines a flag for switching to the new namespace
before demoting the active namespace and guarantees the process will not
have a downtime
type: boolean
outdatedNotification:
$ref: '#/definitions/v1.OutdatedNotification'
description: |-
Expand Down
3 changes: 2 additions & 1 deletion examples/configs/crds/active-promotion-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ metadata:
name: example
spec:
tearDownDuration: 5m
skipTestRunner: false
skipTestRunner: false
noDowntimeGuarantee: false
1 change: 1 addition & 0 deletions examples/configs/crds/config-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ spec:
tearDownDuration: 10s
demotionTimeout: 3m
rollbackTimeout: 5m
noDowntimeGuarantee: false
deployment:
timeout: 5m
engine: helm3
Expand Down
7 changes: 7 additions & 0 deletions examples/starter/crds/active-promotion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ spec:
# use 'false' for using the default setting from Config.yaml <default>
skipTestRunner: false

#! WARNING: noDowntimeGuarantee does not support the service that has a fixed nodePort
# [optional] boolean flag for running an active promotion with no downtime
# when promoting active environment
# use 'true' for running an active promotion with no downtime
# use 'false' for using the default setting from Config.yaml <default>
noDowntimeGuarantee: false

# [optional] name of user who applying active promotion
# default value is empty
promotedBy: <your_name>
6 changes: 6 additions & 0 deletions examples/starter/crds/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ spec:
# default value is 7
maxHistories: 20

#! WARNING: noDowntimeGuarantee does not support the service that has a fixed nodePort
# [optional] specify the noDowntimeGuarantee for running an active promotion with no downtime
# use true for applying noDowntimeGuarantee and it will run promoting an active environment before demote the previous environment
# use false for applying noDowntimeGuarantee and it will run demoting an previous environment before promote an active environment <default>
noDowntimeGuarantee: false

# deployment flow of active environment configuration
deployment:
# how long the active environment should be ready?
Expand Down
7 changes: 7 additions & 0 deletions internal/samsahai/activepromotion/collect_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,16 @@ func (c *controller) collectResult(ctx context.Context, atpComp *s2hv1.ActivePro
return nil
}

if atpComp.Spec.NoDowntimeGuarantee != nil && *atpComp.Spec.NoDowntimeGuarantee {
atpComp.SetState(s2hv1.ActivePromotionActiveEnvironment, "Promoting an active environment")
logger.Info("Collected a result, and start promoting an active environment")
return nil
}

atpComp.Status.SetCondition(s2hv1.ActivePromotionCondActiveDemotionStarted, corev1.ConditionTrue,
"Active demotion has been started")
atpComp.SetState(s2hv1.ActivePromotionDemoting, "Demoting an active environment")
logger.Info("Collected a result, and start demoting an active environment")

return nil
}
Expand Down
21 changes: 16 additions & 5 deletions internal/samsahai/activepromotion/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,33 @@ func New(
}

func (c *controller) setup(ctx context.Context, atpComp *s2hv1.ActivePromotion) error {
config, err := c.s2hCtrl.GetConfigController().Get(atpComp.Name)
if err != nil {
return err
}

// set teardown duration from configuration if it's unset
if atpComp.Spec.TearDownDuration == nil {
duration := c.configs.ActivePromotion.TearDownDuration

config, err := c.s2hCtrl.GetConfigController().Get(atpComp.Name)
if err != nil {
return err
}

if config.Status.Used.ActivePromotion != nil && config.Status.Used.ActivePromotion.TearDownDuration.Duration != 0 {
duration = config.Status.Used.ActivePromotion.TearDownDuration
}

atpComp.Spec.SetTearDownDuration(duration)
}

// set NoDowntimeGuarantee from active-promotion.yaml if the value in the configuration file is not set
if atpComp.Spec.NoDowntimeGuarantee == nil {
atpComp.Spec.NoDowntimeGuarantee = &config.Spec.ActivePromotion.NoDowntimeGuarantee
}

if *atpComp.Spec.NoDowntimeGuarantee {
logger.Info("The active promotion will run promote before demote")
} else {
logger.Info("The active promotion will run demote before promote")
}

c.appendStateLabel(atpComp, stateWaiting)
atpComp.SetState(s2hv1.ActivePromotionWaiting, "Waiting in queue")
logger.Info("activepromotion is waiting in queue", "team", atpComp.Name)
Expand Down
26 changes: 26 additions & 0 deletions internal/samsahai/activepromotion/demote.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,16 @@ func (c *controller) demoteActiveEnvironment(ctx context.Context, atpComp *s2hv1
"team", teamName, "namespace", prevNs)
atpComp.Status.SetCondition(s2hv1.ActivePromotionCondActiveDemoted, corev1.ConditionFalse,
"Failed to demote active environment, active environment has been deleted")

if atpComp.Spec.NoDowntimeGuarantee != nil && *atpComp.Spec.NoDowntimeGuarantee {
atpComp.SetState(s2hv1.ActivePromotionDestroyingPreviousActive,
"Failed to demote active environment")
logger.Info("Demote failed, and start destroying an active environment")
return nil
}

atpComp.SetState(s2hv1.ActivePromotionActiveEnvironment, "Failed to demote active environment")
logger.Info("Demote failed, and start promoting an active environment")

return nil
}
Expand All @@ -48,7 +57,16 @@ func (c *controller) demoteActiveEnvironment(ctx context.Context, atpComp *s2hv1
atpComp.Status.SetDemotionStatus(s2hv1.ActivePromotionDemotionSuccess)
atpComp.Status.SetCondition(s2hv1.ActivePromotionCondActiveDemoted, corev1.ConditionTrue,
"Demoted an active environment successfully")

if atpComp.Spec.NoDowntimeGuarantee != nil && *atpComp.Spec.NoDowntimeGuarantee {
atpComp.SetState(s2hv1.ActivePromotionDestroyingPreviousActive,
"Destroying the previous active environment")
logger.Info("Demote successfully, and start destroying the previous active environment")
return nil
}

atpComp.SetState(s2hv1.ActivePromotionActiveEnvironment, "Promoting an active environment")
logger.Info("Demote successfully, and start promoting an active environment")

return nil
}
Expand Down Expand Up @@ -101,7 +119,15 @@ func (c *controller) checkDemotionTimeout(ctx context.Context, atpComp *s2hv1.Ac
"team", teamName, "namespace", prevNs)
atpComp.Status.SetCondition(s2hv1.ActivePromotionCondActiveDemoted, corev1.ConditionFalse,
"Demoted an active environment timeout, active environment has been deleted")

if atpComp.Spec.NoDowntimeGuarantee != nil && *atpComp.Spec.NoDowntimeGuarantee {
atpComp.SetState(s2hv1.ActivePromotionDestroyingPreviousActive, "Demoted active environment timeout")
logger.Info("Demote timeout, and start destroying an active environment")
return s2herrors.ErrActiveDemotionTimeout
}

atpComp.SetState(s2hv1.ActivePromotionActiveEnvironment, "Demoted active environment timeout")
logger.Info("Demote timeout, and start destroying an active environment")

if err := c.updateActivePromotion(ctx, atpComp); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/samsahai/activepromotion/postactive.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (c *controller) runPostActive(ctx context.Context, atpComp *s2hv1.ActivePro
return err
}

logger.Debug("activepromotionhistory has been created",
logger.Debug("active promotion history has been created",
"team", atpComp.Name, "status", atpComp.Status.Result, "name", histName)
logger.Debug("active promotion report has been sent",
"team", atpComp.Name, "status", atpComp.Status.Result)
Expand Down
14 changes: 12 additions & 2 deletions internal/samsahai/activepromotion/promote.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,19 @@ func (c *controller) promoteActiveEnvironment(ctx context.Context, atpComp *s2hv
"Result has been collected, promoted successfully")
atpComp.Status.SetCondition(s2hv1.ActivePromotionCondActivePromoted, corev1.ConditionTrue,
"Active environment has been promoted")
atpComp.SetState(s2hv1.ActivePromotionDestroyingPreviousActive,
"Destroying the previous active environment")

if atpComp.Spec.NoDowntimeGuarantee != nil && *atpComp.Spec.NoDowntimeGuarantee {
atpComp.Status.SetCondition(s2hv1.ActivePromotionCondActiveDemotionStarted, corev1.ConditionTrue,
"Active demotion has been started")
atpComp.SetState(s2hv1.ActivePromotionDemoting, "Demoting an active environment")
logger.Info("Active environment has been promoted, and start demoting an active environment")
} else {
atpComp.SetState(s2hv1.ActivePromotionDestroyingPreviousActive,
"Destroying the previous active environment")
logger.Info("Active environment has been promoted, and start destroying the previous active environment")
}

// Send the reports when active namespace has been promoted
if err := c.runPostActive(ctx, atpComp); err != nil {
return err
}
Expand Down
5 changes: 5 additions & 0 deletions test/data/crds/env.samsahai.io_activepromotionhistories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ spec:
spec:
description: ActivePromotionSpec defines the desired state of ActivePromotion
properties:
noDowntimeGuarantee:
description: NoDowntimeGuarantee represents a flag for switching
to the new namespace before demoting the active namespace
and guarantees the process will not have a downtime
type: boolean
noOfRetry:
description: NoOfRetry represents how many times this active
promotion process has been run
Expand Down
5 changes: 5 additions & 0 deletions test/data/crds/env.samsahai.io_activepromotions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ spec:
spec:
description: ActivePromotionSpec defines the desired state of ActivePromotion
properties:
noDowntimeGuarantee:
description: NoDowntimeGuarantee represents a flag for switching to
the new namespace before demoting the active namespace and guarantees
the process will not have a downtime
type: boolean
noOfRetry:
description: NoOfRetry represents how many times this active promotion
process has been run
Expand Down
10 changes: 10 additions & 0 deletions test/data/crds/env.samsahai.io_configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ spec:
description: MaxRetry defines max retry counts of active promotion
process in case failure
type: integer
noDowntimeGuarantee:
description: NoDowntimeGuarantee defines a flag for switching to
the new namespace before demoting the active namespace and guarantees
the process will not have a downtime
type: boolean
outdatedNotification:
description: OutdatedNotification defines a configuration of outdated
notification
Expand Down Expand Up @@ -1022,6 +1027,11 @@ spec:
description: MaxRetry defines max retry counts of active promotion
process in case failure
type: integer
noDowntimeGuarantee:
description: NoDowntimeGuarantee defines a flag for switching
to the new namespace before demoting the active namespace
and guarantees the process will not have a downtime
type: boolean
outdatedNotification:
description: OutdatedNotification defines a configuration of
outdated notification
Expand Down

0 comments on commit 9065397

Please sign in to comment.