Skip to content

Commit

Permalink
Merge pull request #163 from keel-hq/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
rusenask authored Mar 17, 2018
2 parents ef4d58b + 9fb820d commit 7ee5b67
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 34 deletions.
14 changes: 8 additions & 6 deletions provider/kubernetes/approvals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ func TestCheckRequestedApproval(t *testing.T) {
v1beta1.Deployment{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{
Name: "dep-1",
Namespace: "xxxx",
Labels: map[string]string{types.KeelPolicyLabel: "all", types.KeelMinimumApprovalsLabel: "1"},
Name: "dep-1",
Namespace: "xxxx",
Labels: map[string]string{types.KeelPolicyLabel: "all", types.KeelMinimumApprovalsLabel: "1"},
Annotations: map[string]string{},
},
v1beta1.DeploymentSpec{
Template: v1.PodTemplateSpec{
Expand Down Expand Up @@ -95,9 +96,10 @@ func TestApprovedCheck(t *testing.T) {
v1beta1.Deployment{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{
Name: "dep-1",
Namespace: "xxxx",
Labels: map[string]string{types.KeelPolicyLabel: "all", types.KeelMinimumApprovalsLabel: "1"},
Name: "dep-1",
Namespace: "xxxx",
Labels: map[string]string{types.KeelPolicyLabel: "all", types.KeelMinimumApprovalsLabel: "1"},
Annotations: map[string]string{},
},
v1beta1.DeploymentSpec{
Template: v1.PodTemplateSpec{
Expand Down
1 change: 1 addition & 0 deletions provider/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ func (p *Provider) updateDeployments(plans []*UpdatePlan) (updated []*v1beta1.De
err = p.forceUpdate(&deployment)
} else {
// regular update
deployment.Annotations["kubernetes.io/change-cause"] = fmt.Sprintf("keel automated update, version %s -> %s", plan.CurrentVersion, plan.NewVersion)
err = p.implementer.Update(&deployment)
}
if err != nil {
Expand Down
42 changes: 24 additions & 18 deletions provider/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,10 @@ func TestProcessEvent(t *testing.T) {
v1beta1.Deployment{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{
Name: "deployment-1",
Namespace: "xxxx",
Labels: map[string]string{types.KeelPolicyLabel: "all"},
Name: "deployment-1",
Namespace: "xxxx",
Labels: map[string]string{types.KeelPolicyLabel: "all"},
Annotations: map[string]string{},
},
v1beta1.DeploymentSpec{
Template: v1.PodTemplateSpec{
Expand All @@ -335,9 +336,10 @@ func TestProcessEvent(t *testing.T) {
v1beta1.Deployment{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{
Name: "deployment-2",
Namespace: "xxxx",
Labels: map[string]string{"whatever": "all"},
Name: "deployment-2",
Namespace: "xxxx",
Labels: map[string]string{"whatever": "all"},
Annotations: map[string]string{},
},
v1beta1.DeploymentSpec{
Template: v1.PodTemplateSpec{
Expand Down Expand Up @@ -393,9 +395,10 @@ func TestProcessEventBuildNumber(t *testing.T) {
v1beta1.Deployment{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{
Name: "deployment-1",
Namespace: "xxxx",
Labels: map[string]string{types.KeelPolicyLabel: "all"},
Name: "deployment-1",
Namespace: "xxxx",
Labels: map[string]string{types.KeelPolicyLabel: "all"},
Annotations: map[string]string{},
},
v1beta1.DeploymentSpec{
Template: v1.PodTemplateSpec{
Expand Down Expand Up @@ -452,9 +455,10 @@ func TestGetImpactedTwoContainersInSameDeployment(t *testing.T) {
v1beta1.Deployment{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{
Name: "dep-1",
Namespace: "xxxx",
Labels: map[string]string{types.KeelPolicyLabel: "all"},
Name: "dep-1",
Namespace: "xxxx",
Labels: map[string]string{types.KeelPolicyLabel: "all"},
Annotations: map[string]string{},
},
v1beta1.DeploymentSpec{
Template: v1.PodTemplateSpec{
Expand Down Expand Up @@ -549,9 +553,10 @@ func TestGetImpactedTwoSameContainersInSameDeployment(t *testing.T) {
v1beta1.Deployment{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{
Name: "dep-1",
Namespace: "xxxx",
Labels: map[string]string{types.KeelPolicyLabel: "all"},
Name: "dep-1",
Namespace: "xxxx",
Labels: map[string]string{types.KeelPolicyLabel: "all"},
Annotations: map[string]string{},
},
v1beta1.DeploymentSpec{
Template: v1.PodTemplateSpec{
Expand All @@ -572,9 +577,10 @@ func TestGetImpactedTwoSameContainersInSameDeployment(t *testing.T) {
v1beta1.Deployment{
meta_v1.TypeMeta{},
meta_v1.ObjectMeta{
Name: "dep-2",
Namespace: "xxxx",
Labels: map[string]string{"whatever": "all"},
Name: "dep-2",
Namespace: "xxxx",
Labels: map[string]string{"whatever": "all"},
Annotations: map[string]string{},
},
v1beta1.DeploymentSpec{
Template: v1.PodTemplateSpec{
Expand Down
13 changes: 7 additions & 6 deletions trigger/pubsub/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,14 @@ func (s *DefaultManager) Start(ctx context.Context) error {
}).Error("trigger.pubsub.manager: scan failed")
}

for _ = range time.Tick(time.Duration(s.scanTick) * time.Second) {
ticker := time.NewTicker(time.Duration(s.scanTick) * time.Second)
defer ticker.Stop()

for {
select {
case <-ctx.Done():
return nil
default:
case <-ticker.C:
log.Debug("performing scan")
err := s.scan(ctx)
if err != nil {
Expand All @@ -77,8 +80,6 @@ func (s *DefaultManager) Start(ctx context.Context) error {
}
}
}

return nil
}

func (s *DefaultManager) scan(ctx context.Context) error {
Expand All @@ -94,8 +95,8 @@ func (s *DefaultManager) scan(ctx context.Context) error {
}

// uri
gcrURI := containerRegistryURI(s.projectID, trackedImage.Image.Registry())
s.ensureSubscription(gcrURI)
// https://cloud.google.com/container-registry/docs/configuring-notifications
s.ensureSubscription("gcr")
}
return nil
}
Expand Down
4 changes: 0 additions & 4 deletions trigger/pubsub/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ import (
// MetadataEndpoint - default metadata server for gcloud pubsub
const MetadataEndpoint = "http://metadata/computeMetadata/v1/instance/attributes/cluster-name"

func containerRegistryURI(projectID, registry string) string {
return registry + "%2F" + projectID
}

func containerRegistrySubName(projectID, topic string) string {
cluster := "unknown"
clusterName, err := clusterName(MetadataEndpoint)
Expand Down

0 comments on commit 7ee5b67

Please sign in to comment.