Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ [minor] Support verifying bundle of components in staging env #37

Merged
merged 12 commits into from
Jun 8, 2020
8 changes: 8 additions & 0 deletions api/v1beta1/config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ type ComponentChart struct {
Version string `json:"version,omitempty"`
}

// ConfigBundles represents a group of component for each bundle
// to verify a group of components of a same bundle together in staging environment
type ConfigBundles map[string][]string

// ConfigStaging represents configuration about staging
type ConfigStaging struct {
// Deployment represents configuration about deploy
Expand Down Expand Up @@ -280,6 +284,10 @@ type ConfigSpec struct {
// Components represents all components that are managed
Components []*Component `json:"components"`

// Bundles represents a group of component for each bundle
// +optional
Bundles ConfigBundles `json:"bundles,omitempty"`

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

Expand Down
6 changes: 5 additions & 1 deletion api/v1beta1/desiredcomponent_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ type DesiredComponentSpec struct {
Name string `json:"name"`
Version string `json:"version"`
Repository string `json:"repository"`

// +Optional
Bundle string `json:"bundle,omitempty"`
}

// DesiredComponentStatus defines the observed state of DesiredComponent
Expand All @@ -47,7 +50,8 @@ type DesiredComponent struct {
func (c *DesiredComponent) IsSame(d *DesiredComponent) bool {
return c.Spec.Name == d.Spec.Name &&
c.Spec.Repository == d.Spec.Repository &&
c.Spec.Version == d.Spec.Version
c.Spec.Version == d.Spec.Version &&
c.Spec.Bundle == d.Spec.Bundle
}

// +kubebuilder:object:root=true
Expand Down
76 changes: 56 additions & 20 deletions api/v1beta1/queue_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,16 @@ const (

// QueueSpec defines the desired state of Queue
type QueueSpec struct {
// Name represents Component name
// Name represents a Component name or bundle name if exist
Name string `json:"name"`

// Repository represents Docker image repository
Repository string `json:"repository"`
// Bundle represents a bundle name of component
// +optional
Bundle string `json:"bundle,omitempty"`

// Version represents Docker image tag version
Version string `json:"version"`
// Components represents a list of components which are deployed
// +optional
Components QueueComponents `json:"components,omitempty"`

// Type represents how we will process this queue
Type QueueType `json:"type"`
Expand All @@ -114,6 +116,19 @@ type Image struct {
Tag string `json:"tag"`
}

type QueueComponents []*QueueComponent

type QueueComponent struct {
// Name represents Component name
Name string `json:"name"`

// Repository represents Docker image repository
Repository string `json:"repository"`

// Version represents Docker image tag version
Version string `json:"version"`
}

type QueueCondition struct {
Type QueueConditionType `json:"type"`
Status corev1.ConditionStatus `json:"status"`
Expand Down Expand Up @@ -191,9 +206,6 @@ type QueueStatus struct {
// NoOfProcessed represents how many time that this queue had been processed
NoOfProcessed int `json:"noOfProcessed,omitempty"`

// ReleaseName defines name of helmrelease
ReleaseName string `json:"releaseName"`

// Conditions contains observations of the resource's state e.g.,
// Queue deployed, being tested
// +optional
Expand Down Expand Up @@ -269,10 +281,20 @@ type Queue struct {
Status QueueStatus `json:"status,omitempty"`
}

func (q *Queue) IsSame(d *Queue) bool {
return q.Spec.Name == d.Spec.Name &&
q.Spec.Repository == d.Spec.Repository &&
q.Spec.Version == d.Spec.Version
func (q *Queue) ContainSameComponent(dName string, dComp *QueueComponent) bool {
if dName != q.Spec.Name {
return false
}

for _, qComp := range q.Spec.Components {
if qComp.Name == dComp.Name &&
qComp.Repository == dComp.Repository &&
qComp.Version == dComp.Version {
return true
}
}

return false
}

func (q *Queue) SetState(state QueueState) {
Expand Down Expand Up @@ -337,7 +359,7 @@ func (ql *QueueList) TopQueueOrder() int {
if len(ql.Items) == 0 {
return 1
}
sort.Sort(ByNoOfOrder(ql.Items))
sort.Sort(QueueByNoOfOrder(ql.Items))
return ql.Items[0].Spec.NoOfOrder - 1
}

Expand All @@ -346,7 +368,7 @@ func (ql *QueueList) LastQueueOrder() int {
if len(ql.Items) == 0 {
return 1
}
sort.Sort(ByNoOfOrder(ql.Items))
sort.Sort(QueueByNoOfOrder(ql.Items))
return ql.Items[len(ql.Items)-1].Spec.NoOfOrder + 1
}

Expand Down Expand Up @@ -378,15 +400,15 @@ func (ql *QueueList) First() *Queue {
return &ql.Items[0]
}

// Sort sorts items
// Sort sorts queue items
func (ql *QueueList) Sort() {
sort.Sort(ByNoOfOrder(ql.Items))
sort.Sort(QueueByNoOfOrder(ql.Items))
}

type ByNoOfOrder []Queue
type QueueByNoOfOrder []Queue

func (q ByNoOfOrder) Len() int { return len(q) }
func (q ByNoOfOrder) Less(i, j int) bool {
func (q QueueByNoOfOrder) Len() int { return len(q) }
func (q QueueByNoOfOrder) Less(i, j int) bool {
now := metav1.Now()

if q[i].Spec.NoOfOrder == q[j].Spec.NoOfOrder {
Expand Down Expand Up @@ -417,7 +439,21 @@ func (q ByNoOfOrder) Less(i, j int) bool {
return q[i].Spec.NoOfOrder < q[j].Spec.NoOfOrder
}

func (q ByNoOfOrder) Swap(i, j int) { q[i], q[j] = q[j], q[i] }
func (q QueueByNoOfOrder) Swap(i, j int) { q[i], q[j] = q[j], q[i] }

// Sort sorts component items
func (qc QueueComponents) Sort() {
sort.Sort(ComponentByName(qc))
}

type ComponentByName []*QueueComponent

func (q ComponentByName) Len() int { return len(q) }
func (q ComponentByName) Less(i, j int) bool {
return q[i].Name < q[j].Name
}

func (q ComponentByName) Swap(i, j int) { q[i], q[j] = q[j], q[i] }

func init() {
SchemeBuilder.Register(&Queue{}, &QueueList{})
Expand Down
162 changes: 141 additions & 21 deletions api/v1beta1/zz_generated.deepcopy.go

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

Loading