Skip to content

Commit

Permalink
✨ [patch] Pre-defined staging queue priority in config (#40)
Browse files Browse the repository at this point in the history
* ☸️ Add priorities config type

* ✨ Support priority queues

* 🐛 Fix queue label

* ✅ Add unit tests

* ✅ Update e2e tests

* 💬 Update queue priority definition
  • Loading branch information
Pohfy123 authored Jun 19, 2020
1 parent b071560 commit 4a345df
Show file tree
Hide file tree
Showing 26 changed files with 1,033 additions and 288 deletions.
5 changes: 5 additions & 0 deletions api/v1beta1/config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ type ConfigSpec struct {
// +optional
Bundles ConfigBundles `json:"bundles,omitempty"`

// PriorityQueues represents a list of bundles/components' name which needs to be prioritized
// the first one has the highest priority and the last one has the lowest priority
// +optional
PriorityQueues []string `json:"priorityQueues,omitempty"`

// Staging represents configuration about staging
Staging *ConfigStaging `json:"staging"`

Expand Down
5 changes: 5 additions & 0 deletions api/v1beta1/zz_generated.deepcopy.go

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

7 changes: 7 additions & 0 deletions config/crds/env.samsahai.io_configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ spec:
description: Envs represents urls of values file per environments ordering
by less priority to high priority
type: object
priorityQueues:
description: PriorityQueues represents a list of bundles/components'
name which needs to be prioritized the first one has the highest priority
and the last one has the lowest priority
items:
type: string
type: array
report:
description: Reporter represents configuration about reporter
properties:
Expand Down
9 changes: 8 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-12 13:43:13.431642 +0700 +07 m=+0.161754686
// 2020-06-18 09:43:32.662924 +0700 +07 m=+0.108614951

package docs

Expand Down Expand Up @@ -1037,6 +1037,13 @@ var doc = `{
"description": "Envs represents urls of values file per environments\nordering by less priority to high priority\n+optional",
"type": "object"
},
"priorityQueues": {
"description": "PriorityQueues represents a list of bundles/components' name which needs to be prioritized\nthe first one has the highest priority and the last one has the lowest priority\n+optional",
"type": "array",
"items": {
"type": "string"
}
},
"report": {
"description": "Reporter represents configuration about reporter\n+optional",
"type": "object",
Expand Down
7 changes: 7 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,13 @@
"description": "Envs represents urls of values file per environments\nordering by less priority to high priority\n+optional",
"type": "object"
},
"priorityQueues": {
"description": "PriorityQueues represents a list of bundles/components' name which needs to be prioritized\nthe first one has the highest priority and the last one has the lowest priority\n+optional",
"type": "array",
"items": {
"type": "string"
}
},
"report": {
"description": "Reporter represents configuration about reporter\n+optional",
"type": "object",
Expand Down
8 changes: 8 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,14 @@ definitions:
ordering by less priority to high priority
+optional
type: object
priorityQueues:
description: |-
PriorityQueues represents a list of bundles/components' name which needs to be prioritized
the first one has the highest priority and the last one has the lowest priority
+optional
items:
type: string
type: array
report:
$ref: '#/definitions/v1beta1.ConfigReporter'
description: |-
Expand Down
11 changes: 11 additions & 0 deletions internal/config/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,17 @@ func (c *controller) GetBundles(configName string) (s2hv1beta1.ConfigBundles, er
return config.Spec.Bundles, nil
}

// GetPriorityQueues returns a list of priority queues which defined in Config
func (c *controller) GetPriorityQueues(configName string) ([]string, error) {
config, err := c.Get(configName)
if err != nil {
logger.Error(err, "cannot get Config", "name", configName)
return []string{}, err
}

return config.Spec.PriorityQueues, nil
}

// Update updates Config CRD
func (c *controller) Update(config *s2hv1beta1.Config) error {
if err := c.client.Update(context.TODO(), config); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions internal/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ type ConfigController interface {
// GetBundles returns a group of components for each bundle
GetBundles(configName string) (s2hv1beta1.ConfigBundles, error)

// GetPriorityQueues returns a list of priority queues which defined in Config
GetPriorityQueues(configName string) ([]string, error)

// Update updates Config CRD
Update(config *s2hv1beta1.Config) error

Expand Down
7 changes: 6 additions & 1 deletion internal/desiredcomponent/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ func (c *controller) Reconcile(req reconcile.Request) (reconcile.Result, error)
logger.Error(err, "cannot get bundle name", "team", c.teamName, "component", comp.Spec.Name)
}

priorityQueues, err := c.s2hClient.GetPriorityQueues(ctx, &samsahairpc.TeamName{Name: c.teamName})
if err != nil {
logger.Error(err, "cannot get priority queues", "team", c.teamName)
}

comps := []*s2hv1beta1.QueueComponent{
{
Name: comp.Spec.Name,
Expand All @@ -135,7 +140,7 @@ func (c *controller) Reconcile(req reconcile.Request) (reconcile.Result, error)
},
}
q := queue.NewUpgradeQueue(c.teamName, req.Namespace, comp.Spec.Name, bundle.Name, comps)
err = c.queueCtrl.Add(q)
err = c.queueCtrl.Add(q, priorityQueues.GetQueues())
if err != nil {
return reconcile.Result{}, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

// QueueController manages updating component queue through CRD
type QueueController interface {
// Add adds Queue
Add(q *v1beta1.Queue) error
// Add adds Queue with priority list
Add(q *v1beta1.Queue, priorityQueues []string) error

// AddTop adds Queue to the top
AddTop(q *v1beta1.Queue) error
Expand Down
Loading

0 comments on commit 4a345df

Please sign in to comment.