Skip to content

Commit

Permalink
using different identifier for approvals, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rusenask committed Apr 30, 2018
1 parent 1a69c21 commit 830dcf1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
10 changes: 6 additions & 4 deletions provider/kubernetes/approvals.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
log "github.com/sirupsen/logrus"
)

func getIdentifier(namespace, name, version string) string {
return namespace + "/" + name + ":" + version
func getApprovalIdentifier(resourceIdentifier, version string) string {
return resourceIdentifier + ":" + version
}

// checkForApprovals - filters out deployments and only passes forward approved ones
Expand Down Expand Up @@ -64,7 +64,8 @@ func (p *Provider) isApproved(event *types.Event, plan *UpdatePlan) (bool, error
}
}

identifier := getIdentifier(plan.Resource.Namespace, plan.Resource.Name, plan.NewVersion)
// identifier := getIdentifier(plan.Resource.Namespace, plan.Resource.Name, plan.NewVersion)
identifier := getApprovalIdentifier(plan.Resource.Identifier, plan.NewVersion)

// checking for existing approval
existing, err := p.approvalManager.Get(identifier)
Expand All @@ -90,7 +91,8 @@ func (p *Provider) isApproved(event *types.Event, plan *UpdatePlan) (bool, error
approval.Delta(),
)

fmt.Println("requesting approval, ns: ", plan.Resource.Namespace)
// fmt.Println("requesting approval, identifier: ", plan.Resource.Namespace)
fmt.Println("requesting approval, identifier: ", identifier)

return false, p.approvalManager.Create(approval)
}
Expand Down
9 changes: 6 additions & 3 deletions provider/kubernetes/approvals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestCheckRequestedApproval(t *testing.T) {
}

// checking approvals
approval, err := provider.approvalManager.Get("xxxx/dep-1:1.1.2")
approval, err := provider.approvalManager.Get("deployment/xxxx/dep-1:1.1.2")
if err != nil {
t.Fatalf("failed to find approval, err: %s", err)
}
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestApprovedCheck(t *testing.T) {

// approving event
err = provider.approvalManager.Create(&types.Approval{
Identifier: "xxxx/dep-1:1.1.2",
Identifier: "deployment/xxxx/dep-1:1.1.2",
VotesReceived: 2,
VotesRequired: 2,
Deadline: time.Now().Add(10 * time.Second),
Expand All @@ -139,7 +139,10 @@ func TestApprovedCheck(t *testing.T) {
t.Fatalf("failed to create approval: %s", err)
}

appr, _ := provider.approvalManager.Get("xxxx/dep-1:1.1.2")
appr, err := provider.approvalManager.Get("deployment/xxxx/dep-1:1.1.2")
if err != nil {
t.Fatalf("failed to get approval: %s", err)
}
if appr.Status() != types.ApprovalStatusApproved {
t.Fatalf("approval not approved")
}
Expand Down
2 changes: 1 addition & 1 deletion provider/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func (p *Provider) createUpdatePlans(repo *types.Repository) ([]*UpdatePlan, err
policy := policies.GetPolicy(labels)
if policy == types.PolicyTypeNone {
// skip
log.Infof("no policy defined, skipping: %s, labels: %s", resource.Identifier, labels)
log.Debugf("no policy defined, skipping: %s, labels: %s", resource.Identifier, labels)
continue
}

Expand Down
3 changes: 1 addition & 2 deletions provider/kubernetes/unversioned_updates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import (
"github.com/keel-hq/keel/types"
"github.com/keel-hq/keel/util/timeutil"

"k8s.io/api/core/v1"
// "k8s.io/api/extensions/apps_v1"
apps_v1 "k8s.io/api/apps/v1"
"k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down
9 changes: 0 additions & 9 deletions provider/kubernetes/versioned_updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ func (p *Provider) checkVersionedDeployment(newVersion *types.Version, policy ty

shouldUpdateDeployment = false

// for idx, c := range deployment.Spec.Template.Spec.Containers {
for idx, c := range resource.Containers() {
// Remove version if any
// containerImageName := versionreg.ReplaceAllString(c.Image, "")

containerImageRef, err := image.Parse(c.Image)
if err != nil {
log.WithFields(log.Fields{
Expand Down Expand Up @@ -141,16 +137,11 @@ func (p *Provider) checkVersionedDeployment(newVersion *types.Version, policy ty
}).Info("provider.kubernetes: checked version, deciding whether to update")

if shouldUpdateContainer {

// c = updateContainer(c, conatinerImageRef, newVersion.String())

if containerImageRef.Registry() == image.DefaultRegistryHostname {
resource.UpdateContainer(idx, fmt.Sprintf("%s:%s", containerImageRef.ShortName(), newVersion.String()))
} else {
resource.UpdateContainer(idx, fmt.Sprintf("%s:%s", containerImageRef.Repository(), newVersion.String()))
}

// deployment.Spec.Template.Spec.Containers[idx] = c
// marking this deployment for update
shouldUpdateDeployment = true

Expand Down

0 comments on commit 830dcf1

Please sign in to comment.