diff --git a/provider/kubernetes/approvals_test.go b/provider/kubernetes/approvals_test.go index 7c04e407..2c2aed17 100644 --- a/provider/kubernetes/approvals_test.go +++ b/provider/kubernetes/approvals_test.go @@ -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{ @@ -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{ diff --git a/provider/kubernetes/kubernetes.go b/provider/kubernetes/kubernetes.go index 7c02d0ac..10cdcecd 100644 --- a/provider/kubernetes/kubernetes.go +++ b/provider/kubernetes/kubernetes.go @@ -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 { diff --git a/provider/kubernetes/kubernetes_test.go b/provider/kubernetes/kubernetes_test.go index 27e9c6f9..bf6e2e35 100644 --- a/provider/kubernetes/kubernetes_test.go +++ b/provider/kubernetes/kubernetes_test.go @@ -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{ @@ -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{ @@ -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{ @@ -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{ @@ -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{ @@ -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{ diff --git a/trigger/pubsub/manager.go b/trigger/pubsub/manager.go index 5d218be6..5686e719 100644 --- a/trigger/pubsub/manager.go +++ b/trigger/pubsub/manager.go @@ -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 { @@ -77,8 +80,6 @@ func (s *DefaultManager) Start(ctx context.Context) error { } } } - - return nil } func (s *DefaultManager) scan(ctx context.Context) error { @@ -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 } diff --git a/trigger/pubsub/util.go b/trigger/pubsub/util.go index b499ddd9..15f2bb64 100644 --- a/trigger/pubsub/util.go +++ b/trigger/pubsub/util.go @@ -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)