Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Merge pull request #3 from bookingcom/143-add-a-rollingout-condition-…
Browse files Browse the repository at this point in the history
…in-application

Add "RollingOut" condition to Application
  • Loading branch information
parhamdoustdar committed Oct 8, 2018
2 parents 3525d85 + 1c5e03d commit 5f24ab9
Show file tree
Hide file tree
Showing 17 changed files with 729 additions and 535 deletions.
7 changes: 1 addition & 6 deletions pkg/apis/shipper/v1/types.go
Expand Up @@ -77,22 +77,17 @@ type ApplicationSpec struct {
}

type ApplicationStatus struct {
State ApplicationState `json:"state"`
Conditions []ApplicationCondition `json:"conditions,omitempty"`
History []string `json:"history,omitempty"`
}

type ApplicationState struct {
RollingOut bool `json:"rollingOut"`
RolloutStep *int32 `json:"rolloutStep,omitempty"`
}

type ApplicationConditionType string

const (
ApplicationConditionTypeValidHistory ApplicationConditionType = "ValidHistory"
ApplicationConditionTypeReleaseSynced ApplicationConditionType = "ReleaseSynced"
ApplicationConditionTypeAborting ApplicationConditionType = "Aborting"
ApplicationConditionTypeRollingOut ApplicationConditionType = "RollingOut"
)

type ApplicationCondition struct {
Expand Down
26 changes: 0 additions & 26 deletions pkg/apis/shipper/v1/zz_generated.deepcopy.go
Expand Up @@ -147,35 +147,9 @@ func (in *ApplicationSpec) DeepCopy() *ApplicationSpec {
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ApplicationState) DeepCopyInto(out *ApplicationState) {
*out = *in
if in.RolloutStep != nil {
in, out := &in.RolloutStep, &out.RolloutStep
if *in == nil {
*out = nil
} else {
*out = new(int32)
**out = **in
}
}
return
}

// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ApplicationState.
func (in *ApplicationState) DeepCopy() *ApplicationState {
if in == nil {
return nil
}
out := new(ApplicationState)
in.DeepCopyInto(out)
return out
}

// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ApplicationStatus) DeepCopyInto(out *ApplicationStatus) {
*out = *in
in.State.DeepCopyInto(&out.State)
if in.Conditions != nil {
in, out := &in.Conditions, &out.Conditions
*out = make([]ApplicationCondition, len(*in))
Expand Down
1 change: 1 addition & 0 deletions pkg/chart/cache/cache_test.go
Expand Up @@ -6,6 +6,7 @@ import (
"strconv"
"strings"
"testing"
"strings"
)

const (
Expand Down
64 changes: 29 additions & 35 deletions pkg/client/listers/shipper/v1/release_expansion.go
@@ -1,14 +1,15 @@
package v1

import (
"fmt"
"sort"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"

shipperv1 "github.com/bookingcom/shipper/pkg/apis/shipper/v1"
shippercontroller "github.com/bookingcom/shipper/pkg/controller"
apputil "github.com/bookingcom/shipper/pkg/util/application"
releaseutil "github.com/bookingcom/shipper/pkg/util/release"
)

// ReleaseListerExpansion allows custom methods to be added to
Expand All @@ -18,64 +19,57 @@ type ReleaseListerExpansion interface{}
// ReleaseNamespaceListerExpansion allows custom methods to be added to
// ReleaseNamespaceLister.
type ReleaseNamespaceListerExpansion interface {
// ReleasesForApplication returns Releases related to the given application
// name ordered by generation.
ReleasesForApplication(appName string) ([]*shipperv1.Release, error)

// ContenderForApplication returns the contender Release for the given
// application name.
ContenderForApplication(appName string) (*shipperv1.Release, error)

// IncumbentForApplication returns the incumbent Release for the given
// application name.
IncumbentForApplication(appName string) (*shipperv1.Release, error)

// ReleaseForInstallationTarget returns the Release associated with given
// InstallationTarget. The relationship is established through owner
// references.
ReleaseForInstallationTarget(it *shipperv1.InstallationTarget) (*shipperv1.Release, error)
}

// ReleasesForApplication returns Releases related to the given application
// name ordered by generation.
func (s releaseNamespaceLister) ReleasesForApplication(appName string) ([]*shipperv1.Release, error) {
selector := labels.Set{shipperv1.AppLabel: appName}.AsSelector()
selectedRels, err := s.List(selector)
if err != nil {
return nil, err
}

type releaseAndGeneration struct {
release *shipperv1.Release
generation int
}

filteredRels := make([]releaseAndGeneration, 0, len(selectedRels))
for _, rel := range selectedRels {
if rel.DeletionTimestamp != nil {
continue
}
g, err := shippercontroller.GetReleaseGeneration(rel)
for _, e := range selectedRels {
_, err := releaseutil.GetGeneration(e)
if err != nil {
return nil, fmt.Errorf(`incomplete Release "%s/%s": %s`, rel.Namespace, rel.Name, err)
return nil, err
}
filteredRels = append(filteredRels, releaseAndGeneration{rel, g})
}

sort.Slice(filteredRels, func(i, j int) bool {
return filteredRels[i].generation < filteredRels[j].generation
})

relsToReturn := make([]*shipperv1.Release, 0, len(filteredRels))
for _, e := range filteredRels {
relsToReturn = append(relsToReturn, e.release)
}

return relsToReturn, nil
return selectedRels, nil
}

// ContenderForApplication returns the contender Release for the given application name.
func (s releaseNamespaceLister) ContenderForApplication(appName string) (*shipperv1.Release, error) {
rels, err := s.ReleasesForApplication(appName)
if err != nil {
return nil, err
}
if len(rels) == 0 {
return nil, fmt.Errorf("no contender found for application %q", appName)
sort.Sort(releaseutil.ByGenerationDescending(rels))
return apputil.GetContender(appName, rels)
}

func (s releaseNamespaceLister) IncumbentForApplication(appName string) (*shipperv1.Release, error) {
rels, err := s.ReleasesForApplication(appName)
if err != nil {
return nil, err
}
return rels[len(rels)-1], nil
sort.Sort(releaseutil.ByGenerationDescending(rels))
return apputil.GetIncumbent(appName, rels)
}

// ReleaseForInstallationTarget returns the Release associated with given
// InstallationTarget. The relationship is established through owner
// references.
func (s releaseNamespaceLister) ReleaseForInstallationTarget(it *shipperv1.InstallationTarget) (*shipperv1.Release, error) {
owner, err := extractOwnerReference(it.ObjectMeta)
if err != nil {
Expand Down
62 changes: 0 additions & 62 deletions pkg/conditions/application.go

This file was deleted.

0 comments on commit 5f24ab9

Please sign in to comment.