diff --git a/api/v1beta1/activepromotion_types.go b/api/v1beta1/activepromotion_types.go index 321abbd4..07c122c9 100644 --- a/api/v1beta1/activepromotion_types.go +++ b/api/v1beta1/activepromotion_types.go @@ -161,7 +161,7 @@ type ActivePromotionStatus struct { IsTimeout bool `json:"isTimeout,omitempty"` // ActiveComponents represents a list of promoted active components // +optional - ActiveComponents []StableComponent `json:"activeComponents,omitempty"` + ActiveComponents map[string]StableComponent `json:"activeComponents,omitempty"` // OutdatedComponents represents map of outdated components // +optional OutdatedComponents map[string]OutdatedComponent `json:"outdatedComponents,omitempty"` @@ -217,12 +217,12 @@ func (s *ActivePromotionStatus) SetPreActiveQueue(qs QueueStatus) { } func (s *ActivePromotionStatus) SetActiveComponents(comps []StableComponent) { - s.ActiveComponents = make([]StableComponent, 0) + s.ActiveComponents = make(map[string]StableComponent) for _, currentComp := range comps { - s.ActiveComponents = append(s.ActiveComponents, StableComponent{ + s.ActiveComponents[currentComp.Spec.Name] = StableComponent{ Spec: currentComp.Spec, Status: currentComp.Status, - }) + } } } diff --git a/api/v1beta1/team_types.go b/api/v1beta1/team_types.go index f898e904..de94bea0 100644 --- a/api/v1beta1/team_types.go +++ b/api/v1beta1/team_types.go @@ -89,11 +89,11 @@ type TeamStatus struct { // StableComponentList represents a list of stable components // +optional - StableComponents []StableComponent `json:"stableComponents,omitempty"` + StableComponents map[string]StableComponent `json:"stableComponents,omitempty"` // ActiveComponents represents a list of stable components in active namespace // +optional - ActiveComponents []StableComponent `json:"activeComponents,omitempty"` + ActiveComponents map[string]StableComponent `json:"activeComponents,omitempty"` // Conditions contains observations of the resource's state e.g., // Team namespace is created, destroyed @@ -108,15 +108,17 @@ type TeamStatus struct { DesiredComponentImageCreatedTime map[string]map[string]DesiredImageTime `json:"desiredComponentImageCreatedTime,omitempty"` } -func (ts *TeamStatus) GetStableComponent(stableCompName string) *StableComponent { - for i := 0; i < len(ts.StableComponents); i++ { - comp := ts.StableComponents[i] - if comp.Spec.Name == stableCompName { - return &comp - } +func (ts *TeamStatus) GetStableComponent(stableCompName string) StableComponent { + if len(ts.StableComponents) == 0 { + return StableComponent{} + } + + stableComp, ok := ts.StableComponents[stableCompName] + if !ok { + return StableComponent{} } - return nil + return stableComp } // SetStableComponents sets stable components @@ -125,49 +127,47 @@ func (ts *TeamStatus) SetStableComponents(stableComp *StableComponent, isDeleted return false } - for i := 0; i < len(ts.StableComponents); i++ { - comp := ts.StableComponents[i] - if isDeleted { - if comp.Spec.Name == stableComp.Spec.Name { - ts.StableComponents[i] = ts.StableComponents[len(ts.StableComponents)-1] - ts.StableComponents = ts.StableComponents[:len(ts.StableComponents)-1] - return true - } - - continue - } - - if comp.Spec.Name == stableComp.Spec.Name { - if comp.Spec != stableComp.Spec { - ts.StableComponents[i].Spec = stableComp.Spec - ts.StableComponents[i].Status = stableComp.Status - return true - } - - return false - } + if ts.StableComponents == nil { + ts.StableComponents = make(map[string]StableComponent) } - if !isDeleted { + tStableComp, ok := ts.StableComponents[stableComp.Name] + if !ok && !isDeleted { // add new stable component - ts.StableComponents = append(ts.StableComponents, StableComponent{ + ts.StableComponents[stableComp.Name] = StableComponent{ Spec: stableComp.Spec, Status: stableComp.Status, - }) + } return true } + if ok { + if isDeleted { + delete(ts.StableComponents, stableComp.Name) + return true + } + + if tStableComp.Spec != stableComp.Spec { + sComp := StableComponent{ + Spec: stableComp.Spec, + Status: stableComp.Status, + } + ts.StableComponents[stableComp.Name] = sComp + return true + } + } + return false } // SetActiveComponents sets active components -func (ts *TeamStatus) SetActiveComponents(comps []StableComponent) { - ts.ActiveComponents = make([]StableComponent, 0) - for _, currentComp := range comps { - ts.ActiveComponents = append(ts.ActiveComponents, StableComponent{ +func (ts *TeamStatus) SetActiveComponents(comps map[string]StableComponent) { + ts.ActiveComponents = make(map[string]StableComponent) + for compName, currentComp := range comps { + ts.ActiveComponents[compName] = StableComponent{ Spec: currentComp.Spec, Status: currentComp.Status, - }) + } } } diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index ae7ed55a..c6475437 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -257,9 +257,9 @@ func (in *ActivePromotionStatus) DeepCopyInto(out *ActivePromotionStatus) { } if in.ActiveComponents != nil { in, out := &in.ActiveComponents, &out.ActiveComponents - *out = make([]StableComponent, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) + *out = make(map[string]StableComponent, len(*in)) + for key, val := range *in { + (*out)[key] = *val.DeepCopy() } } if in.OutdatedComponents != nil { @@ -1634,16 +1634,16 @@ func (in *TeamStatus) DeepCopyInto(out *TeamStatus) { out.Namespace = in.Namespace if in.StableComponents != nil { in, out := &in.StableComponents, &out.StableComponents - *out = make([]StableComponent, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) + *out = make(map[string]StableComponent, len(*in)) + for key, val := range *in { + (*out)[key] = *val.DeepCopy() } } if in.ActiveComponents != nil { in, out := &in.ActiveComponents, &out.ActiveComponents - *out = make([]StableComponent, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) + *out = make(map[string]StableComponent, len(*in)) + for key, val := range *in { + (*out)[key] = *val.DeepCopy() } } if in.Conditions != nil { diff --git a/config/crds/env.samsahai.io_activepromotionhistories.yaml b/config/crds/env.samsahai.io_activepromotionhistories.yaml index f0b0ef68..51ab3d0d 100644 --- a/config/crds/env.samsahai.io_activepromotionhistories.yaml +++ b/config/crds/env.samsahai.io_activepromotionhistories.yaml @@ -66,9 +66,7 @@ spec: ActivePromotion properties: activeComponents: - description: ActiveComponents represents a list of promoted - active components - items: + additionalProperties: description: StableComponent is the Schema for the stablecomponents API properties: @@ -120,7 +118,9 @@ spec: type: string type: object type: object - type: array + description: ActiveComponents represents a list of promoted + active components + type: object activePromotionHistoryName: description: ActivePromotionHistoryName represents created ActivePromotionHistoryName name diff --git a/config/crds/env.samsahai.io_activepromotions.yaml b/config/crds/env.samsahai.io_activepromotions.yaml index a388bf54..ca3069ce 100644 --- a/config/crds/env.samsahai.io_activepromotions.yaml +++ b/config/crds/env.samsahai.io_activepromotions.yaml @@ -43,8 +43,7 @@ spec: description: ActivePromotionStatus defines the observed state of ActivePromotion properties: activeComponents: - description: ActiveComponents represents a list of promoted active components - items: + additionalProperties: description: StableComponent is the Schema for the stablecomponents API properties: @@ -96,7 +95,8 @@ spec: type: string type: object type: object - type: array + description: ActiveComponents represents a list of promoted active components + type: object activePromotionHistoryName: description: ActivePromotionHistoryName represents created ActivePromotionHistoryName name diff --git a/config/crds/env.samsahai.io_teams.yaml b/config/crds/env.samsahai.io_teams.yaml index 6b3b3446..c797e5a2 100644 --- a/config/crds/env.samsahai.io_teams.yaml +++ b/config/crds/env.samsahai.io_teams.yaml @@ -139,9 +139,7 @@ spec: description: TeamStatus defines the observed state of Team properties: activeComponents: - description: ActiveComponents represents a list of stable components - in active namespace - items: + additionalProperties: description: StableComponent is the Schema for the stablecomponents API properties: @@ -193,7 +191,9 @@ spec: type: string type: object type: object - type: array + description: ActiveComponents represents a list of stable components + in active namespace + type: object conditions: description: Conditions contains observations of the resource's state e.g., Team namespace is created, destroyed @@ -232,8 +232,7 @@ spec: type: string type: object stableComponents: - description: StableComponentList represents a list of stable components - items: + additionalProperties: description: StableComponent is the Schema for the stablecomponents API properties: @@ -285,7 +284,8 @@ spec: type: string type: object type: object - type: array + description: StableComponentList represents a list of stable components + type: object type: object type: object version: v1beta1 diff --git a/docs/docs.go b/docs/docs.go index f2f31a1a..02463284 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1,6 +1,6 @@ // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT // This file was generated by swaggo/swag at -// 2020-04-01 21:22:44.065972 +0700 +07 m=+0.125130578 +// 2020-04-16 13:30:12.640214 +0700 +07 m=+0.112977605 package docs @@ -733,10 +733,7 @@ var doc = `{ "properties": { "activeComponents": { "description": "ActiveComponents represents a list of promoted active components\n+optional", - "type": "array", - "items": { - "$ref": "#/definitions/v1beta1.StableComponent" - } + "type": "object" }, "activePromotionHistoryName": { "description": "ActivePromotionHistoryName represents created ActivePromotionHistoryName name\n+optional", @@ -1547,10 +1544,7 @@ var doc = `{ "properties": { "activeComponents": { "description": "ActiveComponents represents a list of stable components in active namespace\n+optional", - "type": "array", - "items": { - "$ref": "#/definitions/v1beta1.StableComponent" - } + "type": "object" }, "conditions": { "description": "Conditions contains observations of the resource's state e.g.,\nTeam namespace is created, destroyed\n+optional\n+patchMergeKey=type\n+patchStrategy=merge", @@ -1570,10 +1564,7 @@ var doc = `{ }, "stableComponents": { "description": "StableComponentList represents a list of stable components\n+optional", - "type": "array", - "items": { - "$ref": "#/definitions/v1beta1.StableComponent" - } + "type": "object" } } }, diff --git a/docs/swagger.json b/docs/swagger.json index 79d7fa03..7e2d64f8 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -712,10 +712,7 @@ "properties": { "activeComponents": { "description": "ActiveComponents represents a list of promoted active components\n+optional", - "type": "array", - "items": { - "$ref": "#/definitions/v1beta1.StableComponent" - } + "type": "object" }, "activePromotionHistoryName": { "description": "ActivePromotionHistoryName represents created ActivePromotionHistoryName name\n+optional", @@ -1526,10 +1523,7 @@ "properties": { "activeComponents": { "description": "ActiveComponents represents a list of stable components in active namespace\n+optional", - "type": "array", - "items": { - "$ref": "#/definitions/v1beta1.StableComponent" - } + "type": "object" }, "conditions": { "description": "Conditions contains observations of the resource's state e.g.,\nTeam namespace is created, destroyed\n+optional\n+patchMergeKey=type\n+patchStrategy=merge", @@ -1549,10 +1543,7 @@ }, "stableComponents": { "description": "StableComponentList represents a list of stable components\n+optional", - "type": "array", - "items": { - "$ref": "#/definitions/v1beta1.StableComponent" - } + "type": "object" } } }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 2c625654..c50b055f 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -62,9 +62,7 @@ definitions: description: |- ActiveComponents represents a list of promoted active components +optional - items: - $ref: '#/definitions/v1beta1.StableComponent' - type: array + type: object activePromotionHistoryName: description: |- ActivePromotionHistoryName represents created ActivePromotionHistoryName name @@ -740,9 +738,7 @@ definitions: description: |- ActiveComponents represents a list of stable components in active namespace +optional - items: - $ref: '#/definitions/v1beta1.StableComponent' - type: array + type: object conditions: description: |- Conditions contains observations of the resource's state e.g., @@ -767,9 +763,7 @@ definitions: description: |- StableComponentList represents a list of stable components +optional - items: - $ref: '#/definitions/v1beta1.StableComponent' - type: array + type: object type: object v1beta1.Teamcity: properties: diff --git a/internal/samsahai.go b/internal/samsahai.go index 5fa790fb..f41dcc34 100644 --- a/internal/samsahai.go +++ b/internal/samsahai.go @@ -124,7 +124,7 @@ type SamsahaiController interface { CreatePreActiveEnvironment(teamName, namespace string) error // PromoteActiveEnvironment switches environment from pre-active to active and stores current active components - PromoteActiveEnvironment(teamComp *s2hv1beta1.Team, namespace string, comps []s2hv1beta1.StableComponent) error + PromoteActiveEnvironment(teamComp *s2hv1beta1.Team, namespace string, comps map[string]s2hv1beta1.StableComponent) error // DestroyActiveEnvironment destroys active environment when active demotion is failure. DestroyActiveEnvironment(teamName, namespace string) error diff --git a/internal/samsahai/checker/samsahai/check_test.go b/internal/samsahai/checker/samsahai/check_test.go index c470f527..d43522b0 100644 --- a/internal/samsahai/checker/samsahai/check_test.go +++ b/internal/samsahai/checker/samsahai/check_test.go @@ -82,8 +82,8 @@ var _ = Describe("", func() { obj, _ := util.MustParseYAMLtoRuntimeObject(yamlTeam) team, _ := obj.(*s2hv1beta1.Team) - team.Status.StableComponents = []s2hv1beta1.StableComponent{ - { + team.Status.StableComponents = map[string]s2hv1beta1.StableComponent{ + "redis": { ObjectMeta: metav1.ObjectMeta{ Name: "redis", Namespace: namespace, @@ -94,7 +94,7 @@ var _ = Describe("", func() { Version: "10.0.0-r0", }, }, - { + "mariadb": { ObjectMeta: metav1.ObjectMeta{ Name: "mariadb", Namespace: namespace, diff --git a/internal/samsahai/checker/samsahai/checker.go b/internal/samsahai/checker/samsahai/checker.go index 92b739c9..a9b6f218 100644 --- a/internal/samsahai/checker/samsahai/checker.go +++ b/internal/samsahai/checker/samsahai/checker.go @@ -84,18 +84,9 @@ func (c *checker) GetVersion(repository, name, pattern string) (string, error) { return "", errors.Wrap(err, "cannot get team") } - var stableComp *v1beta1.StableComponent // create the stable components map - for i := range team.Status.StableComponents { - c := &team.Status.StableComponents[i] - if c.Spec.Name == name { - stableComp = c - break - } - } - - if stableComp == nil { - // ignore component not found + stableComp, ok := team.Status.StableComponents[name] + if !ok { continue } diff --git a/internal/samsahai/controller.go b/internal/samsahai/controller.go index d45acdfa..11b8b996 100644 --- a/internal/samsahai/controller.go +++ b/internal/samsahai/controller.go @@ -328,7 +328,7 @@ func (c *controller) CreatePreActiveEnvironment(teamName, namespace string) erro func (c *controller) PromoteActiveEnvironment( teamComp *s2hv1beta1.Team, namespace string, - comps []s2hv1beta1.StableComponent, + comps map[string]s2hv1beta1.StableComponent, ) error { preActiveNamespace := teamComp.Status.Namespace.PreActive activeNamespace := teamComp.Status.Namespace.Active @@ -374,7 +374,7 @@ func (c *controller) PromoteActiveEnvironment( preActiveNamespace + " (team pre-active namespace), so this pre-active namespace cannot be switched") } -func (c *controller) storeActiveComponentsToTeam(teamComp *s2hv1beta1.Team, comps []s2hv1beta1.StableComponent) error { +func (c *controller) storeActiveComponentsToTeam(teamComp *s2hv1beta1.Team, comps map[string]s2hv1beta1.StableComponent) error { teamComp.Status.SetActiveComponents(comps) return nil } diff --git a/internal/stablecomponent/controller.go b/internal/stablecomponent/controller.go index d536ffa2..fbbbcdf7 100644 --- a/internal/stablecomponent/controller.go +++ b/internal/stablecomponent/controller.go @@ -213,7 +213,7 @@ func (c *controller) Reconcile(req cr.Request) (cr.Result, error) { func (c *controller) detectSpecChanged(stableComp *s2hv1beta1.StableComponent, teamComp *s2hv1beta1.Team) bool { if stableComp != nil { teamStableComp := teamComp.Status.GetStableComponent(stableComp.Name) - if teamStableComp != nil { + if teamStableComp.Name != "" { if teamStableComp.Spec == stableComp.Spec { return false } diff --git a/test/e2e/samsahai/ctrl.go b/test/e2e/samsahai/ctrl.go index a89273a5..15cf0898 100644 --- a/test/e2e/samsahai/ctrl.go +++ b/test/e2e/samsahai/ctrl.go @@ -43,8 +43,13 @@ import ( ) const ( - verifyTimeout10 = 10 * time.Second - verifyNSCreatedTimeout = 15 * time.Second + verifyTime1s = 1 * time.Second + verifyTime5s = 5 * time.Second + verifyTime10s = 10 * time.Second + verifyTime15s = 15 * time.Second + verifyTime30s = 30 * time.Second + verifyTime60s = 60 * time.Second + verifyNSCreatedTimeout = verifyTime15s promoteTimeOut = 220 * time.Second ) @@ -427,7 +432,7 @@ var _ = Describe("Main Controller [e2e]", func() { By("Deleting all StableComponents") err = runtimeClient.DeleteAllOf(ctx, &s2hv1beta1.StableComponent{}, crclient.InNamespace(stgNamespace)) Expect(err).NotTo(HaveOccurred()) - err = wait.PollImmediate(1*time.Second, verifyTimeout10, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { stableList := s2hv1beta1.StableComponentList{} err = runtimeClient.List(ctx, &stableList, &crclient.ListOptions{Namespace: stgNamespace}) if err != nil && errors.IsNotFound(err) { @@ -444,7 +449,7 @@ var _ = Describe("Main Controller [e2e]", func() { By("Deleting all Teams") err = runtimeClient.DeleteAllOf(ctx, &s2hv1beta1.Team{}, crclient.MatchingLabels(testLabels)) Expect(err).NotTo(HaveOccurred()) - err = wait.PollImmediate(1*time.Second, verifyTimeout10, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { teamList := s2hv1beta1.TeamList{} listOpt := &crclient.ListOptions{LabelSelector: labels.SelectorFromSet(testLabels)} err = runtimeClient.List(ctx, &teamList, listOpt) @@ -462,7 +467,7 @@ var _ = Describe("Main Controller [e2e]", func() { By("Deleting all Configs") err = runtimeClient.DeleteAllOf(ctx, &s2hv1beta1.Config{}, crclient.MatchingLabels(testLabels)) Expect(err).NotTo(HaveOccurred()) - err = wait.PollImmediate(1*time.Second, verifyTimeout10, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { configList := s2hv1beta1.ConfigList{} listOpt := &crclient.ListOptions{LabelSelector: labels.SelectorFromSet(testLabels)} err = runtimeClient.List(ctx, &configList, listOpt) @@ -480,7 +485,7 @@ var _ = Describe("Main Controller [e2e]", func() { By("Deleting active namespace") atvNs := activeNamespace _ = runtimeClient.Delete(context.TODO(), &atvNs) - err = wait.PollImmediate(1*time.Second, verifyTimeout10, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { namespace := corev1.Namespace{} err = runtimeClient.Get(ctx, types.NamespacedName{Name: atvNamespace}, &namespace) if err != nil && errors.IsNotFound(err) { @@ -492,7 +497,7 @@ var _ = Describe("Main Controller [e2e]", func() { By("Deleting all ActivePromotions") err = runtimeClient.DeleteAllOf(ctx, &s2hv1beta1.ActivePromotion{}, crclient.MatchingLabels(testLabels)) Expect(err).NotTo(HaveOccurred()) - err = wait.PollImmediate(1*time.Second, verifyTimeout10, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { atpList := s2hv1beta1.ActivePromotionList{} listOpt := &crclient.ListOptions{LabelSelector: labels.SelectorFromSet(testLabels)} err = runtimeClient.List(ctx, &atpList, listOpt) @@ -546,7 +551,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(runtimeClient.Create(ctx, &team)).To(BeNil()) By("Verifying staging related objects has been created") - err = wait.PollImmediate(1*time.Second, verifyNSCreatedTimeout, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyNSCreatedTimeout, func() (ok bool, err error) { namespace := corev1.Namespace{} err = runtimeClient.Get(ctx, types.NamespacedName{Name: stgNamespace}, &namespace) if err != nil { @@ -625,7 +630,7 @@ var _ = Describe("Main Controller [e2e]", func() { By("Checking stable component has been set") teamComp := s2hv1beta1.Team{} Expect(runtimeClient.Get(ctx, types.NamespacedName{Name: team.Name}, &teamComp)) - teamSpecStableComps := teamComp.Status.StableComponents[0].Spec + teamSpecStableComps := teamComp.Status.StableComponents[mariaDBCompName].Spec Expect(teamSpecStableComps.Name).To(Equal(stableAtvMariaDB.Spec.Name)) Expect(teamSpecStableComps.Repository).To(Equal(stableAtvMariaDB.Spec.Repository)) Expect(teamSpecStableComps.Version).To(Equal(stableAtvMariaDB.Spec.Version)) @@ -713,7 +718,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(len(stableComps.Items)).To(Equal(1)) By("previous active namespace should be deleted") - err = wait.PollImmediate(1*time.Second, promoteTimeOut, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, promoteTimeOut, func() (ok bool, err error) { namespace := corev1.Namespace{} err = runtimeClient.Get(ctx, types.NamespacedName{Name: atvNamespace}, &namespace) if err != nil && errors.IsNotFound(err) { @@ -725,7 +730,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(err).NotTo(HaveOccurred(), "Delete previous namespace error") By("ActivePromotion should be deleted") - err = wait.PollImmediate(1*time.Second, 45*time.Second, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { atpTemp := s2hv1beta1.ActivePromotion{} err = runtimeClient.Get(ctx, types.NamespacedName{Name: atp.Name}, &atpTemp) if err != nil && errors.IsNotFound(err) { @@ -822,7 +827,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(runtimeClient.Create(ctx, &atvNs)).To(BeNil()) By("Verifying namespace and config have been created") - err = wait.PollImmediate(1*time.Second, verifyNSCreatedTimeout, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyNSCreatedTimeout, func() (ok bool, err error) { namespace := corev1.Namespace{} if err := runtimeClient.Get(ctx, types.NamespacedName{Name: stgNamespace}, &namespace); err != nil { return false, nil @@ -846,7 +851,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(runtimeClient.Create(ctx, &atp)).To(BeNil()) By("Waiting ActivePromotion state to be `PromotingActiveEnvironment`") - err = wait.PollImmediate(1*time.Second, verifyTimeout10, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { atpComp := s2hv1beta1.ActivePromotion{} if err := runtimeClient.Get(ctx, types.NamespacedName{Name: teamName}, &atpComp); err != nil { return false, nil @@ -898,7 +903,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(runtimeClient.Create(ctx, &config3)).To(BeNil()) By("Verifying all teams have been created") - err = wait.PollImmediate(1*time.Second, verifyTimeout10, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { teamList := s2hv1beta1.TeamList{} listOpt := &crclient.ListOptions{LabelSelector: labels.SelectorFromSet(testLabels)} if err := runtimeClient.List(ctx, &teamList, listOpt); err != nil { @@ -933,14 +938,13 @@ var _ = Describe("Main Controller [e2e]", func() { atpQ2.Name = teamForQ2 Expect(runtimeClient.Create(ctx, &atpQ2)).To(BeNil()) - time.Sleep(1 * time.Second) - + time.Sleep(verifyTime1s) atpQ3 := activePromotion atpQ3.Name = teamForQ3 Expect(runtimeClient.Create(ctx, &atpQ3)).To(BeNil()) By("Waiting ActivePromotion Q1 state to be `Deploying`, other ActivePromotion states to be waiting") - err = wait.PollImmediate(1*time.Second, verifyTimeout10, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { atpCompQ1 := s2hv1beta1.ActivePromotion{} if err := runtimeClient.Get(ctx, types.NamespacedName{Name: teamForQ1}, &atpCompQ1); err != nil { return false, nil @@ -969,7 +973,7 @@ var _ = Describe("Main Controller [e2e]", func() { atpCompQ2 := s2hv1beta1.ActivePromotion{} Expect(runtimeClient.Get(ctx, types.NamespacedName{Name: teamForQ2}, &atpCompQ2)).To(BeNil()) Expect(runtimeClient.Delete(context.TODO(), &atpCompQ2)).NotTo(HaveOccurred()) - err = wait.PollImmediate(1*time.Second, verifyTimeout10, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { atpTemp := s2hv1beta1.ActivePromotion{} err = runtimeClient.Get(ctx, types.NamespacedName{Name: teamForQ2}, &atpTemp) if err != nil && errors.IsNotFound(err) { @@ -996,7 +1000,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(runtimeClient.Create(ctx, &deActiveQ)).To(BeNil()) By("Verifying delete ActivePromotion Q1") - err = wait.PollImmediate(1*time.Second, 30*time.Second, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime30s, func() (ok bool, err error) { atpTemp := s2hv1beta1.ActivePromotion{} err = runtimeClient.Get(ctx, types.NamespacedName{Name: teamForQ1}, &atpTemp) if err != nil && errors.IsNotFound(err) { @@ -1008,7 +1012,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(err).NotTo(HaveOccurred(), "Delete active promotion for Team1 error") By("Checking ActivePromotion Q3 should be run") - err = wait.PollImmediate(1*time.Second, verifyTimeout10, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { atpTemp := s2hv1beta1.ActivePromotion{} if err := runtimeClient.Get(ctx, types.NamespacedName{Name: teamForQ3}, &atpTemp); err != nil { return false, nil @@ -1047,7 +1051,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(runtimeClient.Create(ctx, &smd)).To(BeNil()) By("Verifying namespace and config have been created") - err = wait.PollImmediate(1*time.Second, verifyNSCreatedTimeout, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyNSCreatedTimeout, func() (ok bool, err error) { namespace := corev1.Namespace{} if err := runtimeClient.Get(ctx, types.NamespacedName{Name: stgNamespace}, &namespace); err != nil { return false, nil @@ -1068,7 +1072,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(runtimeClient.Create(ctx, &atp)).To(BeNil()) By("Waiting ActivePromotion state to be `Deploying`") - err = wait.PollImmediate(1*time.Second, verifyTimeout10, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { atpComp := s2hv1beta1.ActivePromotion{} if err := runtimeClient.Get(ctx, types.NamespacedName{Name: teamName}, &atpComp); err != nil { return false, nil @@ -1101,7 +1105,7 @@ var _ = Describe("Main Controller [e2e]", func() { By("pre-active namespace should be deleted") preActiveNs := atpComp.Status.TargetNamespace - err = wait.PollImmediate(1*time.Second, 15*time.Second, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime15s, func() (ok bool, err error) { namespace := corev1.Namespace{} err = runtimeClient.Get(ctx, types.NamespacedName{Name: preActiveNs}, &namespace) if err != nil && errors.IsNotFound(err) { @@ -1113,7 +1117,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(err).NotTo(HaveOccurred(), "Delete pre-active namespace error") By("ActivePromotion should be deleted") - err = wait.PollImmediate(1*time.Second, verifyTimeout10, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { atpTemp := s2hv1beta1.ActivePromotion{} err = runtimeClient.Get(ctx, types.NamespacedName{Name: atp.Name}, &atpTemp) if err != nil && errors.IsNotFound(err) { @@ -1152,7 +1156,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(runtimeClient.Create(ctx, &team)).To(BeNil()) By("Verifying namespace and config have been created") - err = wait.PollImmediate(1*time.Second, verifyNSCreatedTimeout, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyNSCreatedTimeout, func() (ok bool, err error) { namespace := corev1.Namespace{} if err := runtimeClient.Get(ctx, types.NamespacedName{Name: stgNamespace}, &namespace); err != nil { return false, nil @@ -1177,7 +1181,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(runtimeClient.Create(ctx, &atp)).To(BeNil()) By("ActivePromotion should be deleted") - err = wait.PollImmediate(1*time.Second, verifyTimeout10, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { atpTemp := s2hv1beta1.ActivePromotion{} err = runtimeClient.Get(ctx, types.NamespacedName{Name: atp.Name}, &atpTemp) if err != nil && errors.IsNotFound(err) { @@ -1203,7 +1207,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(runtimeClient.Create(ctx, &team)).To(BeNil()) By("Verifying namespace and config have been created") - err = wait.PollImmediate(1*time.Second, verifyNSCreatedTimeout, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyNSCreatedTimeout, func() (ok bool, err error) { team := s2hv1beta1.Team{} if err := runtimeClient.Get(ctx, types.NamespacedName{Name: teamName}, &team); err != nil { return false, nil @@ -1228,7 +1232,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(runtimeClient.Delete(ctx, &team)).To(BeNil()) By("Verifying Config should be deleted") - err = wait.PollImmediate(1*time.Second, 15*time.Second, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime15s, func() (ok bool, err error) { config := s2hv1beta1.Config{} err = runtimeClient.Get(ctx, types.NamespacedName{Name: teamName}, &config) if err != nil && errors.IsNotFound(err) { @@ -1251,7 +1255,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(runtimeClient.Create(ctx, &team)).To(BeNil()) By("Team should be error if missing Config") - err = wait.PollImmediate(1*time.Second, verifyTimeout10, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { team := s2hv1beta1.Team{} if err := runtimeClient.Get(ctx, types.NamespacedName{Name: teamName}, &team); err != nil { return false, nil @@ -1294,7 +1298,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(runtimeClient.Create(ctx, &team)).To(BeNil()) By("Verifying namespace and config have been created") - err = wait.PollImmediate(1*time.Second, verifyNSCreatedTimeout, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyNSCreatedTimeout, func() (ok bool, err error) { namespace := corev1.Namespace{} if err := runtimeClient.Get(ctx, types.NamespacedName{Name: stgNamespace}, &namespace); err != nil { return false, nil @@ -1319,7 +1323,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(err).NotTo(HaveOccurred()) By("Verifying DesiredComponent has been created") - err = wait.PollImmediate(1*time.Second, 30*time.Second, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime30s, func() (ok bool, err error) { _, _ = utilhttp.Post(server.URL+"/webhook/component", jsonData) dc := s2hv1beta1.DesiredComponent{} @@ -1365,7 +1369,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(runtimeClient.Create(ctx, &team)).To(BeNil()) By("Verifying namespace and config have been created") - err = wait.PollImmediate(1*time.Second, verifyNSCreatedTimeout, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyNSCreatedTimeout, func() (ok bool, err error) { namespace := corev1.Namespace{} if err := runtimeClient.Get(ctx, types.NamespacedName{Name: stgNamespace}, &namespace); err != nil { return false, nil @@ -1399,7 +1403,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(runtimeClient.Get(ctx, types.NamespacedName{Name: teamName}, &team)).NotTo(HaveOccurred()) By("Verifying DesiredComponentImageCreatedTime has been updated") - err = wait.PollImmediate(1*time.Second, verifyTimeout10, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { teamComp := s2hv1beta1.Team{} if err := runtimeClient.Get(ctx, types.NamespacedName{Name: team.Name}, &teamComp); err != nil { return false, nil @@ -1465,7 +1469,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(runtimeClient.Create(ctx, &teamComp)).To(BeNil()) By("Verifying namespace and config have been created") - err = wait.PollImmediate(1*time.Second, verifyNSCreatedTimeout, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyNSCreatedTimeout, func() (ok bool, err error) { namespace := corev1.Namespace{} if err := runtimeClient.Get(ctx, types.NamespacedName{Name: stgNamespace}, &namespace); err != nil { return false, nil @@ -1493,7 +1497,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(err).NotTo(HaveOccurred()) By("Verifying redis DesiredComponent has been created") - err = wait.PollImmediate(1*time.Second, 50*time.Second, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, 50*time.Second, func() (ok bool, err error) { _, _ = utilhttp.Post(server.URL+"/webhook/component", jsonDataRedis) dRedis := s2hv1beta1.DesiredComponent{} if err = runtimeClient.Get(ctx, types.NamespacedName{Name: redisCompName, Namespace: stgNamespace}, &dRedis); err != nil { @@ -1541,7 +1545,7 @@ var _ = Describe("Main Controller [e2e]", func() { configComp.Spec.Components = []*s2hv1beta1.Component{{Name: redisCompName}} Expect(runtimeClient.Update(ctx, &configComp)).To(BeNil()) - time.Sleep(1 * time.Second) + time.Sleep(verifyTime1s) By("Checking DesiredComponents") dRedis := s2hv1beta1.DesiredComponent{} Expect(runtimeClient.Get(ctx, types.NamespacedName{Namespace: stgNamespace, Name: redisCompName}, &dRedis)).To(BeNil()) @@ -1550,7 +1554,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(errors.IsNotFound(err)).To(BeTrue()) By("Checking TeamDesiredComponents") - err = wait.PollImmediate(1*time.Second, 5*time.Second, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime5s, func() (ok bool, err error) { teamComp = s2hv1beta1.Team{} if err = runtimeClient.Get(ctx, types.NamespacedName{Name: teamName}, &teamComp); err != nil { return false, nil @@ -1569,14 +1573,23 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(err).NotTo(HaveOccurred(), "Verify TeamDesiredComponent error") By("Checking Queues") - qRedis := s2hv1beta1.Queue{} - Expect(runtimeClient.Get(ctx, types.NamespacedName{Namespace: stgNamespace, Name: redisCompName}, &qRedis)).To(BeNil()) - qWordpress := s2hv1beta1.Queue{} - err = runtimeClient.Get(ctx, types.NamespacedName{Namespace: stgNamespace, Name: wordpressCompName}, &qWordpress) - Expect(errors.IsNotFound(err)).To(BeTrue()) + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { + qRedis := s2hv1beta1.Queue{} + if err = runtimeClient.Get(ctx, types.NamespacedName{Namespace: stgNamespace, Name: redisCompName}, &qRedis); err != nil { + return false, nil + } + + qWordpress := s2hv1beta1.Queue{} + if err = runtimeClient.Get(ctx, types.NamespacedName{Namespace: stgNamespace, Name: wordpressCompName}, &qWordpress); err != nil && !errors.IsNotFound(err) { + return false, nil + } + + return true, nil + }) + Expect(err).NotTo(HaveOccurred(), "Verify StableComponents error") By("Checking StableComponents") - err = wait.PollImmediate(1*time.Second, 10*time.Second, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { sRedis := s2hv1beta1.StableComponent{} if err = runtimeClient.Get(ctx, types.NamespacedName{Namespace: stgNamespace, Name: redisCompName}, &sRedis); err != nil { return false, nil @@ -1618,7 +1631,7 @@ var _ = Describe("Main Controller [e2e]", func() { Expect(runtimeClient.Create(ctx, &team)).To(BeNil()) By("Verifying namespace and config have been created") - err = wait.PollImmediate(1*time.Second, verifyTimeout10, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { namespace := corev1.Namespace{} if err := runtimeClient.Get(ctx, types.NamespacedName{Name: stgNamespace}, &namespace); err != nil { return false, nil @@ -1754,7 +1767,7 @@ var _ = Describe("Main Controller Promote On Team Creation [e2e]", func() { By("Deleting all StableComponents") err = runtimeClient.DeleteAllOf(ctx, &s2hv1beta1.StableComponent{}, crclient.InNamespace(stgNamespace)) Expect(err).NotTo(HaveOccurred()) - err = wait.PollImmediate(1*time.Second, verifyTimeout10, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { stableList := s2hv1beta1.StableComponentList{} err = runtimeClient.List(ctx, &stableList, &crclient.ListOptions{Namespace: stgNamespace}) if err != nil && errors.IsNotFound(err) { @@ -1771,7 +1784,7 @@ var _ = Describe("Main Controller Promote On Team Creation [e2e]", func() { By("Deleting all Teams") err = runtimeClient.DeleteAllOf(ctx, &s2hv1beta1.Team{}, crclient.MatchingLabels(testLabels)) Expect(err).NotTo(HaveOccurred()) - err = wait.PollImmediate(1*time.Second, verifyTimeout10, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { teamList := s2hv1beta1.TeamList{} listOpt := &crclient.ListOptions{LabelSelector: labels.SelectorFromSet(testLabels)} err = runtimeClient.List(ctx, &teamList, listOpt) @@ -1789,7 +1802,7 @@ var _ = Describe("Main Controller Promote On Team Creation [e2e]", func() { By("Deleting all Configs") err = runtimeClient.DeleteAllOf(ctx, &s2hv1beta1.Config{}, crclient.MatchingLabels(testLabels)) Expect(err).NotTo(HaveOccurred()) - err = wait.PollImmediate(1*time.Second, verifyTimeout10, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { configList := s2hv1beta1.ConfigList{} listOpt := &crclient.ListOptions{LabelSelector: labels.SelectorFromSet(testLabels)} err = runtimeClient.List(ctx, &configList, listOpt) @@ -1807,7 +1820,7 @@ var _ = Describe("Main Controller Promote On Team Creation [e2e]", func() { By("Deleting all ActivePromotions") err = runtimeClient.DeleteAllOf(ctx, &s2hv1beta1.ActivePromotion{}, crclient.MatchingLabels(testLabels)) Expect(err).NotTo(HaveOccurred()) - err = wait.PollImmediate(1*time.Second, verifyTimeout10, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { atpList := s2hv1beta1.ActivePromotionList{} listOpt := &crclient.ListOptions{LabelSelector: labels.SelectorFromSet(testLabels)} err = runtimeClient.List(ctx, &atpList, listOpt) @@ -1850,7 +1863,7 @@ var _ = Describe("Main Controller Promote On Team Creation [e2e]", func() { Expect(runtimeClient.Create(ctx, &team)).To(BeNil()) By("Verifying namespace and config have been created") - err = wait.PollImmediate(1*time.Second, verifyNSCreatedTimeout, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyNSCreatedTimeout, func() (ok bool, err error) { namespace := corev1.Namespace{} if err := runtimeClient.Get(ctx, types.NamespacedName{Name: stgNamespace}, &namespace); err != nil { return false, nil @@ -1925,7 +1938,7 @@ var _ = Describe("Main Controller Promote On Team Creation [e2e]", func() { } By("ActivePromotion should be deleted") - err = wait.PollImmediate(1*time.Second, promoteTimeOut, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, promoteTimeOut, func() (ok bool, err error) { atpTemp := s2hv1beta1.ActivePromotion{} err = runtimeClient.Get(ctx, types.NamespacedName{Name: team.Name}, &atpTemp) if err != nil && errors.IsNotFound(err) { @@ -1994,7 +2007,7 @@ var _ = Describe("Main Controller Promote On Team Creation [e2e]", func() { Expect(runtimeClient.Create(ctx, &team)).To(BeNil()) By("Verifying namespace and config have been created") - err = wait.PollImmediate(1*time.Second, verifyNSCreatedTimeout, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyNSCreatedTimeout, func() (ok bool, err error) { namespace := corev1.Namespace{} if err := runtimeClient.Get(ctx, types.NamespacedName{Name: stgNamespace}, &namespace); err != nil { return false, nil @@ -2035,7 +2048,7 @@ var _ = Describe("Main Controller Promote On Team Creation [e2e]", func() { Expect(atpRes.Status.PreviousActiveNamespace).To(BeEmpty()) By("Waiting ActivePromotion state to be `Deploying`") - err = wait.PollImmediate(1*time.Second, 60*time.Second, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime60s, func() (ok bool, err error) { atpComp := s2hv1beta1.ActivePromotion{} if err := runtimeClient.Get(ctx, types.NamespacedName{Name: atpRes.Name}, &atpComp); err != nil { return false, nil @@ -2063,7 +2076,7 @@ var _ = Describe("Main Controller Promote On Team Creation [e2e]", func() { By("pre-active namespace should be deleted") preActiveNs := atpComp.Status.TargetNamespace - err = wait.PollImmediate(1*time.Second, 15*time.Second, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime15s, func() (ok bool, err error) { namespace := corev1.Namespace{} err = runtimeClient.Get(ctx, types.NamespacedName{Name: preActiveNs}, &namespace) if err != nil && errors.IsNotFound(err) { @@ -2075,7 +2088,7 @@ var _ = Describe("Main Controller Promote On Team Creation [e2e]", func() { Expect(err).NotTo(HaveOccurred(), "Delete pre-active namespace error") By("ActivePromotion should be deleted") - err = wait.PollImmediate(1*time.Second, verifyTimeout10, func() (ok bool, err error) { + err = wait.PollImmediate(verifyTime1s, verifyTime10s, func() (ok bool, err error) { atpTemp := s2hv1beta1.ActivePromotion{} err = runtimeClient.Get(ctx, types.NamespacedName{Name: team.Name}, &atpTemp) if err != nil && errors.IsNotFound(err) {