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

Take ignore policy into account when working with automated resources #1749

Merged
merged 2 commits into from
Feb 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/weaveworks/flux"
"github.com/weaveworks/flux/resource"
"github.com/weaveworks/flux/ssh"
"github.com/weaveworks/flux/policy"
)

// Constants for workload ready status. These are defined here so that
Expand Down Expand Up @@ -69,6 +70,7 @@ type Controller struct {
// in this field.
Antecedent flux.ResourceID
Labels map[string]string
Policies policy.Set
Rollout RolloutStatus
// Errors during the recurring sync from the Git repository to the
// cluster will surface here.
Expand Down
16 changes: 16 additions & 0 deletions cluster/kubernetes/resourcekinds.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package kubernetes

import (
"strings"

apiapps "k8s.io/api/apps/v1"
apibatch "k8s.io/api/batch/v1beta1"
apiv1 "k8s.io/api/core/v1"
Expand All @@ -12,6 +14,7 @@ import (
"github.com/weaveworks/flux/image"
fhr_v1beta1 "github.com/weaveworks/flux/integrations/apis/flux.weave.works/v1beta1"
fhr_v1alpha2 "github.com/weaveworks/flux/integrations/apis/helm.integrations.flux.weave.works/v1alpha2"
"github.com/weaveworks/flux/policy"
"github.com/weaveworks/flux/resource"
)

Expand Down Expand Up @@ -85,13 +88,26 @@ func (pc podController) toClusterController(resourceID flux.ResourceID) cluster.
}
}

var policies policy.Set
for k, v := range pc.GetAnnotations() {
if strings.HasPrefix(k, kresource.PolicyPrefix) {
p := strings.TrimPrefix(k, kresource.PolicyPrefix)
if v == "true" {
policies = policies.Add(policy.Policy(p))
} else {
policies = policies.Set(policy.Policy(p), v)
}
}
}

return cluster.Controller{
ID: resourceID,
Status: pc.status,
Rollout: pc.rollout,
SyncError: pc.syncError,
Antecedent: antecedent,
Labels: pc.GetLabels(),
Policies: policies,
Containers: cluster.ContainersOrExcuse{Containers: clusterContainers, Excuse: excuse},
}
}
Expand Down
11 changes: 6 additions & 5 deletions daemon/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (d *Daemon) pollForNewImages(logger log.Logger) {

ctx := context.Background()

candidateServices, err := d.getUnlockedAutomatedResources(ctx)
candidateServices, err := d.getAllowedAutomatedResources(ctx)
if err != nil {
logger.Log("error", errors.Wrap(err, "getting unlocked automated resources"))
return
Expand Down Expand Up @@ -95,9 +95,10 @@ func (r resources) IDs() (ids []flux.ResourceID) {
return ids
}

// getUnlockedAutomatedServices returns all the resources that are
// both automated, and not locked.
func (d *Daemon) getUnlockedAutomatedResources(ctx context.Context) (resources, error) {
// getAllowedAutomatedResources returns all the resources that are
// automated but do not have policies set to restrain them from
// getting updated.
func (d *Daemon) getAllowedAutomatedResources(ctx context.Context) (resources, error) {
resources, _, err := d.getResources(ctx)
if err != nil {
return nil, err
Expand All @@ -106,7 +107,7 @@ func (d *Daemon) getUnlockedAutomatedResources(ctx context.Context) (resources,
result := map[flux.ResourceID]resource.Resource{}
for _, resource := range resources {
policies := resource.Policy()
if policies.Has(policy.Automated) && !policies.Has(policy.Locked) {
if policies.Has(policy.Automated) && !policies.Has(policy.Locked) && !policies.Has(policy.Ignore) {
result[resource.ResourceID()] = resource
}
}
Expand Down
6 changes: 5 additions & 1 deletion update/automated.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ func (a *Automated) CalculateRelease(rc ReleaseContext, logger log.Logger) ([]*C
prefilters := []ControllerFilter{
&IncludeFilter{a.serviceIDs()},
}
postfilters := []ControllerFilter{
&LockedFilter{},
&IgnoreFilter{},
}

result := Result{}
updates, err := rc.SelectServices(result, prefilters, nil)
updates, err := rc.SelectServices(result, prefilters, postfilters)
if err != nil {
return nil, nil, err
}
Expand Down
14 changes: 14 additions & 0 deletions update/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

const (
Locked = "locked"
Ignore = "ignore"
NotIncluded = "not included"
Excluded = "excluded"
DifferentImage = "a different image"
Expand Down Expand Up @@ -89,3 +90,16 @@ func (f *LockedFilter) Filter(u ControllerUpdate) ControllerResult {
}
return ControllerResult{}
}

type IgnoreFilter struct {
}

func (f *IgnoreFilter) Filter(u ControllerUpdate) ControllerResult {
hiddeco marked this conversation as resolved.
Show resolved Hide resolved
if u.Controller.Policies.Has(policy.Ignore) {
return ControllerResult{
Status: ReleaseStatusSkipped,
Error: Ignore,
}
}
return ControllerResult{}
}
2 changes: 1 addition & 1 deletion update/release_containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (s ReleaseContainersSpec) filters() ([]ControllerFilter, []ControllerFilter
pre := []ControllerFilter{&IncludeFilter{IDs: rids}}

if !s.Force {
return pre, []ControllerFilter{&LockedFilter{}}
return pre, []ControllerFilter{&LockedFilter{}, &IgnoreFilter{}}
}
return pre, []ControllerFilter{}
}
Expand Down
2 changes: 1 addition & 1 deletion update/release_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (s ReleaseImageSpec) filters(rc ReleaseContext) ([]ControllerFilter, []Cont

// Filter out locked controllers unless given a specific controller(s) and forced
if !(len(ids) > 0 && s.Force) {
postfilters = append(postfilters, &LockedFilter{})
postfilters = append(postfilters, &LockedFilter{}, &IgnoreFilter{})
}

return prefilters, postfilters, nil
Expand Down