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

Rename resource method Policy() to Policies() #1775

Merged
merged 1 commit into from
Feb 28, 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: 1 addition & 1 deletion cluster/kubernetes/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func PolicyFromAnnotations(annotations map[string]string) policy.Set {
return set
}

func (o baseObject) Policy() policy.Set {
func (o baseObject) Policies() policy.Set {
return PolicyFromAnnotations(o.Meta.Annotations)
}

Expand Down
2 changes: 1 addition & 1 deletion cluster/kubernetes/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (c *Cluster) Sync(spec cluster.SyncSet) error {
csum := sha1.Sum(res.Bytes())
checkHex := hex.EncodeToString(csum[:])
checksums[id] = checkHex
if res.Policy().Has(policy.Ignore) {
if res.Policies().Has(policy.Ignore) {
logger.Log("info", "not applying resource; ignore annotation in file", "resource", res.ResourceID(), "source", res.Source())
continue
}
Expand Down
4 changes: 2 additions & 2 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (d *Daemon) ListServicesWithOptions(ctx context.Context, opts v11.ListServi
readOnly := v6.ReadOnlyOK
var policies policy.Set
if resource, ok := resources[service.ID.String()]; ok {
policies = resource.Policy()
policies = resource.Policies()
}
switch {
case policies == nil:
Expand Down Expand Up @@ -637,7 +637,7 @@ func getServiceContainers(service cluster.Controller, imageRepos update.ImageRep
imageRepo := c.Image.Name
var policies policy.Set
if resource != nil {
policies = resource.Policy()
policies = resource.Policies()
}
tagPattern := policy.GetTagPattern(policies, c.Name)

Expand Down
2 changes: 1 addition & 1 deletion daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ func TestDaemon_PolicyUpdate(t *testing.T) {
if err != nil {
t.Fatalf("Error: %s", err.Error())
}
return len(m[svc].Policy()) > 0
return len(m[svc].Policies()) > 0
}, "Waiting for new annotation")
}

Expand Down
4 changes: 2 additions & 2 deletions daemon/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (d *Daemon) pollForNewImages(logger log.Logger) {
for _, service := range services {
var p policy.Set
if resource, ok := candidateServices[service.ID]; ok {
p = resource.Policy()
p = resource.Policies()
}
containers:
for _, container := range service.ContainersOrNil() {
Expand Down Expand Up @@ -106,7 +106,7 @@ func (d *Daemon) getAllowedAutomatedResources(ctx context.Context) (resources, e

result := map[flux.ResourceID]resource.Resource{}
for _, resource := range resources {
policies := resource.Policy()
policies := resource.Policies()
if policies.Has(policy.Automated) && !policies.Has(policy.Locked) && !policies.Has(policy.Ignore) {
result[resource.ResourceID()] = resource
}
Expand Down
4 changes: 2 additions & 2 deletions policy/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ func TestJSON(t *testing.T) {
policy := boolPolicy.Set(LockedUser, "user@example.com")

if !(policy.Has(Ignore) && policy.Has(Locked)) {
t.Errorf("Policy did not include those added")
t.Errorf("Policies did not include those added")
}
if val, ok := policy.Get(LockedUser); !ok || val != "user@example.com" {
t.Errorf("Policy did not include policy that was set")
t.Errorf("Policies did not include policy that was set")
}

bs, err := json.Marshal(policy)
Expand Down
2 changes: 1 addition & 1 deletion resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
// For the minute we just care about
type Resource interface {
ResourceID() flux.ResourceID // name, to correlate with what's in the cluster
Policy() policy.Set // policy for this resource; e.g., whether it is locked, automated, ignored
Policies() policy.Set // policy for this resource; e.g., whether it is locked, automated, ignored
Source() string // where did this come from (informational)
Bytes() []byte // the definition, for sending to cluster.Sync
}
Expand Down
2 changes: 1 addition & 1 deletion update/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type LockedFilter struct {
}

func (f *LockedFilter) Filter(u ControllerUpdate) ControllerResult {
if u.Resource.Policy().Has(policy.Locked) {
if u.Resource.Policies().Has(policy.Locked) {
return ControllerResult{
Status: ReleaseStatusSkipped,
Error: Locked,
Expand Down
2 changes: 1 addition & 1 deletion update/release_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (s ReleaseImageSpec) calculateImageUpdates(rc ReleaseContext, candidates []
// Use the container's filter if the spec does not want to force release, or
// all images requested
if !s.Force || s.ImageSpec == ImageSpecLatest {
if pattern, ok := u.Resource.Policy().Get(policy.TagPrefix(container.Name)); ok {
if pattern, ok := u.Resource.Policies().Get(policy.TagPrefix(container.Name)); ok {
tagPattern = policy.NewPattern(pattern)
}
}
Expand Down