Skip to content

Commit

Permalink
✨ [patch] Support skip running test on demand (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pohfy123 authored Jun 12, 2020
1 parent 5bf3d02 commit b071560
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 15 deletions.
4 changes: 4 additions & 0 deletions api/v1beta1/activepromotion_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ type ActivePromotionSpec struct {
// TearDownDuration represents duration before tear down the previous active namespace
// +optional
TearDownDuration *metav1.Duration `json:"tearDownDuration,omitempty"`

// SkipTestRunner represents a flag for skipping running pre-active test
// +optional
SkipTestRunner bool `json:"skipTestRunner,omitempty"`
}

func (s *ActivePromotionSpec) SetTearDownDuration(d metav1.Duration) {
Expand Down
4 changes: 4 additions & 0 deletions api/v1beta1/queue_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ type QueueSpec struct {

// TeamName represents team owner of the queue
TeamName string `json:"teamName"`

// SkipTestRunner represents a flag for skipping running test
// +optional
SkipTestRunner bool `json:"skipTestRunner,omitempty"`
}

type Image struct {
Expand Down
4 changes: 4 additions & 0 deletions config/crds/env.samsahai.io_activepromotionhistories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ spec:
spec:
description: ActivePromotionSpec defines the desired state of ActivePromotion
properties:
skipTestRunner:
description: SkipTestRunner represents a flag for skipping running
pre-active test
type: boolean
tearDownDuration:
description: TearDownDuration represents duration before tear
down the previous active namespace
Expand Down
4 changes: 4 additions & 0 deletions config/crds/env.samsahai.io_activepromotions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ spec:
spec:
description: ActivePromotionSpec defines the desired state of ActivePromotion
properties:
skipTestRunner:
description: SkipTestRunner represents a flag for skipping running pre-active
test
type: boolean
tearDownDuration:
description: TearDownDuration represents duration before tear down the
previous active namespace
Expand Down
4 changes: 4 additions & 0 deletions config/crds/env.samsahai.io_queuehistories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ spec:
description: NoOfRetry defines how many times this component
has been tested
type: integer
skipTestRunner:
description: SkipTestRunner represents a flag for skipping running
test
type: boolean
teamName:
description: TeamName represents team owner of the queue
type: string
Expand Down
3 changes: 3 additions & 0 deletions config/crds/env.samsahai.io_queues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ spec:
description: NoOfRetry defines how many times this component has been
tested
type: integer
skipTestRunner:
description: SkipTestRunner represents a flag for skipping running test
type: boolean
teamName:
description: TeamName represents team owner of the queue
type: string
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
// 2020-06-05 09:08:53.407712 +0700 +07 m=+0.253929246
// 2020-06-12 13:43:13.431642 +0700 +07 m=+0.161754686

package docs

Expand Down Expand Up @@ -722,6 +722,10 @@ var doc = `{
"v1beta1.ActivePromotionSpec": {
"type": "object",
"properties": {
"skipTestRunner": {
"description": "SkipTestRunner represents a flag for skipping running pre-active test\n+optional",
"type": "boolean"
},
"tearDownDuration": {
"description": "TearDownDuration represents duration before tear down the previous active namespace\n+optional",
"type": "string"
Expand Down Expand Up @@ -1329,6 +1333,10 @@ var doc = `{
"description": "NoOfRetry defines how many times this component has been tested\n+optional",
"type": "integer"
},
"skipTestRunner": {
"description": "SkipTestRunner represents a flag for skipping running test\n+optional",
"type": "boolean"
},
"teamName": {
"description": "TeamName represents team owner of the queue",
"type": "string"
Expand Down
8 changes: 8 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,10 @@
"v1beta1.ActivePromotionSpec": {
"type": "object",
"properties": {
"skipTestRunner": {
"description": "SkipTestRunner represents a flag for skipping running pre-active test\n+optional",
"type": "boolean"
},
"tearDownDuration": {
"description": "TearDownDuration represents duration before tear down the previous active namespace\n+optional",
"type": "string"
Expand Down Expand Up @@ -1308,6 +1312,10 @@
"description": "NoOfRetry defines how many times this component has been tested\n+optional",
"type": "integer"
},
"skipTestRunner": {
"description": "SkipTestRunner represents a flag for skipping running test\n+optional",
"type": "boolean"
},
"teamName": {
"description": "TeamName represents team owner of the queue",
"type": "string"
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
v1beta1.ActivePromotionSpec:
properties:
skipTestRunner:
description: |-
SkipTestRunner represents a flag for skipping running pre-active test
+optional
type: boolean
tearDownDuration:
description: |-
TearDownDuration represents duration before tear down the previous active namespace
Expand Down Expand Up @@ -567,6 +572,11 @@ definitions:
NoOfRetry defines how many times this component has been tested
+optional
type: integer
skipTestRunner:
description: |-
SkipTestRunner represents a flag for skipping running test
+optional
type: boolean
teamName:
description: TeamName represents team owner of the queue
type: string
Expand Down
7 changes: 4 additions & 3 deletions internal/queue/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,16 @@ func (c *controller) resetQueueOrderWithCurrentQueue(ql *s2hv1beta1.QueueList, c
}

// EnsurePreActiveComponents ensures that components with were deployed with `pre-active` config and tested
func EnsurePreActiveComponents(c client.Client, teamName, namespace string) (q *s2hv1beta1.Queue, err error) {
func EnsurePreActiveComponents(c client.Client, teamName, namespace string, skipTest bool) (q *s2hv1beta1.Queue, err error) {
q = &s2hv1beta1.Queue{
ObjectMeta: metav1.ObjectMeta{
Name: string(s2hv1beta1.EnvPreActive),
Namespace: namespace,
},
Spec: s2hv1beta1.QueueSpec{
Type: s2hv1beta1.QueueTypePreActive,
TeamName: teamName,
Type: s2hv1beta1.QueueTypePreActive,
TeamName: teamName,
SkipTestRunner: skipTest,
},
}

Expand Down
4 changes: 2 additions & 2 deletions internal/samsahai/activepromotion/collect_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import (
func (c *controller) collectResult(ctx context.Context, atpComp *s2hv1beta1.ActivePromotion) error {
teamName := atpComp.Name
targetNs := c.getTargetNamespace(atpComp)
q, err := queue.EnsurePreActiveComponents(c.client, teamName, targetNs)
q, err := queue.EnsurePreActiveComponents(c.client, teamName, targetNs, atpComp.Spec.SkipTestRunner)
if err != nil {
return errors.Wrapf(err, "cannot ensure pre-active components, namespace %s", targetNs)
}

if !atpComp.IsActivePromotionCanceled() && !atpComp.Status.IsTimeout {
// to save pre-active queue after pre-active queue finished
q, err = c.ensurePreActiveComponentsTested(teamName, targetNs)
q, err = c.ensurePreActiveComponentsTested(teamName, targetNs, atpComp.Spec.SkipTestRunner)
if err != nil {
return errors.Wrapf(err, "cannot ensure pre-active components finished, namespace %s", targetNs)
}
Expand Down
12 changes: 6 additions & 6 deletions internal/samsahai/activepromotion/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func (c *controller) deployComponentsToTargetNamespace(atpComp *s2hv1beta1.ActivePromotion) error {
teamName := atpComp.Name
targetNs := c.getTargetNamespace(atpComp)
q, err := c.ensurePreActiveComponentsDeployed(teamName, targetNs)
q, err := c.ensurePreActiveComponentsDeployed(teamName, targetNs, atpComp.Spec.SkipTestRunner)
if err != nil {
return err
}
Expand All @@ -35,8 +35,8 @@ func (c *controller) deployComponentsToTargetNamespace(atpComp *s2hv1beta1.Activ
return nil
}

func (c *controller) ensurePreActiveComponentsDeployed(teamName, targetNs string) (*s2hv1beta1.Queue, error) {
q, err := queue.EnsurePreActiveComponents(c.client, teamName, targetNs)
func (c *controller) ensurePreActiveComponentsDeployed(teamName, targetNs string, skipTest bool) (*s2hv1beta1.Queue, error) {
q, err := queue.EnsurePreActiveComponents(c.client, teamName, targetNs, skipTest)
if err != nil {
return nil, errors.Wrapf(err, "cannot ensure pre-active components, namespace %s", targetNs)
}
Expand All @@ -56,7 +56,7 @@ func (c *controller) ensurePreActiveComponentsDeployed(teamName, targetNs string
func (c *controller) testPreActiveEnvironment(atpComp *s2hv1beta1.ActivePromotion) error {
teamName := atpComp.Name
targetNs := c.getTargetNamespace(atpComp)
q, err := c.ensurePreActiveComponentsTested(teamName, targetNs)
q, err := c.ensurePreActiveComponentsTested(teamName, targetNs, atpComp.Spec.SkipTestRunner)
if err != nil {
return err
}
Expand All @@ -79,8 +79,8 @@ func (c *controller) testPreActiveEnvironment(atpComp *s2hv1beta1.ActivePromotio
return nil
}

func (c *controller) ensurePreActiveComponentsTested(teamName, targetNs string) (*s2hv1beta1.Queue, error) {
q, err := queue.EnsurePreActiveComponents(c.client, teamName, targetNs)
func (c *controller) ensurePreActiveComponentsTested(teamName, targetNs string, skipTest bool) (*s2hv1beta1.Queue, error) {
q, err := queue.EnsurePreActiveComponents(c.client, teamName, targetNs, skipTest)
if err != nil {
return nil, errors.Wrapf(err, "cannot ensure pre-active components, namespace %s", targetNs)
}
Expand Down
12 changes: 11 additions & 1 deletion internal/staging/start_testrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,18 @@ func (c *controller) checkTestTimeout(queue *s2hv1beta1.Queue, testingTimeout me

// checkTestConfig checks test configuration and return testRunner
func (c *controller) checkTestConfig(queue *s2hv1beta1.Queue) (skipTest bool, testRunner internal.StagingTestRunner, err error) {
testConfig := c.getTestConfiguration(queue)
if queue.Spec.SkipTestRunner {
if err = c.updateTestQueueCondition(
queue,
v1.ConditionTrue,
"skip running test"); err != nil {
return
}

return true, nil, nil
}

testConfig := c.getTestConfiguration(queue)
if testConfig == nil {
if err = c.updateTestQueueCondition(
queue,
Expand Down
5 changes: 3 additions & 2 deletions test/e2e/staging/ctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,10 @@ var _ = Describe("[e2e] Staging controller", func() {

By("Ensure Pre Active Components")
redisServiceName := fmt.Sprintf("%s-redis-master", namespace)
skipTest := true

err = wait.PollImmediate(2*time.Second, deployTimeout, func() (ok bool, err error) {
queue, err := queue.EnsurePreActiveComponents(client, teamName, namespace)
queue, err := queue.EnsurePreActiveComponents(client, teamName, namespace, skipTest)
if err != nil {
logger.Error(err, "cannot ensure pre-active components")
return false, nil
Expand All @@ -497,7 +498,7 @@ var _ = Describe("[e2e] Staging controller", func() {
})
Expect(err).NotTo(HaveOccurred(), "Ensure Pre Active error")

q, err := queue.EnsurePreActiveComponents(client, teamName, namespace)
q, err := queue.EnsurePreActiveComponents(client, teamName, namespace, skipTest)
Expect(err).NotTo(HaveOccurred())
Expect(q.IsDeploySuccess()).To(BeTrue())
Expect(q.IsTestSuccess()).To(BeTrue())
Expand Down

0 comments on commit b071560

Please sign in to comment.