From 30ecd420920f76f297281ab083c1447e1ed8c3da Mon Sep 17 00:00:00 2001 From: Karolis Rusenas Date: Sun, 2 Jul 2017 08:44:08 +0100 Subject: [PATCH 1/3] dont crash on untagged images --- provider/kubernetes/kubernetes_test.go | 93 ++++++++++++++++++++++++++ util/version/version.go | 2 +- util/version/version_test.go | 5 ++ 3 files changed, 99 insertions(+), 1 deletion(-) diff --git a/provider/kubernetes/kubernetes_test.go b/provider/kubernetes/kubernetes_test.go index fa1c75e6..12f569ec 100644 --- a/provider/kubernetes/kubernetes_test.go +++ b/provider/kubernetes/kubernetes_test.go @@ -492,3 +492,96 @@ func TestGetImpactedTwoSameContainersInSameDeployment(t *testing.T) { } } + +func TestGetImpactedUntaggedImage(t *testing.T) { + fp := &fakeImplementer{} + fp.namespaces = &v1.NamespaceList{ + Items: []v1.Namespace{ + v1.Namespace{ + meta_v1.TypeMeta{}, + meta_v1.ObjectMeta{Name: "xxxx"}, + v1.NamespaceSpec{}, + v1.NamespaceStatus{}, + }, + }, + } + fp.deploymentList = &v1beta1.DeploymentList{ + Items: []v1beta1.Deployment{ + v1beta1.Deployment{ + meta_v1.TypeMeta{}, + meta_v1.ObjectMeta{ + Name: "dep-1", + Namespace: "xxxx", + Labels: map[string]string{types.KeelPolicyLabel: "all"}, + }, + v1beta1.DeploymentSpec{ + Template: v1.PodTemplateSpec{ + Spec: v1.PodSpec{ + Containers: []v1.Container{ + v1.Container{ + Image: "gcr.io/v2-namespace/hello-world", + }, + }, + }, + }, + }, + v1beta1.DeploymentStatus{}, + }, + v1beta1.Deployment{ + meta_v1.TypeMeta{}, + meta_v1.ObjectMeta{ + Name: "dep-2", + Namespace: "xxxx", + Labels: map[string]string{types.KeelPolicyLabel: "all"}, + }, + v1beta1.DeploymentSpec{ + Template: v1.PodTemplateSpec{ + Spec: v1.PodSpec{ + Containers: []v1.Container{ + v1.Container{ + Image: "gcr.io/v2-namespace/hello-world:1.1.1", + }, + }, + }, + }, + }, + v1beta1.DeploymentStatus{}, + }, + }, + } + + provider, err := NewProvider(fp) + if err != nil { + t.Fatalf("failed to get provider: %s", err) + } + + // creating "new version" event + repo := &types.Repository{ + Name: "gcr.io/v2-namespace/hello-world", + Tag: "1.1.2", + } + + deps, err := provider.impactedDeployments(repo) + if err != nil { + t.Errorf("failed to get deployments: %s", err) + } + + if len(deps) != 1 { + t.Errorf("expected to find 1 deployment but found %s", len(deps)) + } + + found := false + for _, c := range deps[0].Spec.Template.Spec.Containers { + + containerImageName := versionreg.ReplaceAllString(c.Image, "") + + if containerImageName == repo.Name { + found = true + } + } + + if !found { + t.Errorf("couldn't find expected deployment in impacted deployment list") + } + +} diff --git a/util/version/version.go b/util/version/version.go index 237115f3..6e9e110b 100644 --- a/util/version/version.go +++ b/util/version/version.go @@ -38,7 +38,7 @@ func GetVersion(version string) (*types.Version, error) { // GetVersionFromImageName - get version from image name func GetVersionFromImageName(name string) (*types.Version, error) { parts := strings.Split(name, ":") - if len(parts) > 0 { + if len(parts) > 1 { return GetVersion(parts[1]) } diff --git a/util/version/version_test.go b/util/version/version_test.go index 2fe52802..1fcdc5d5 100644 --- a/util/version/version_test.go +++ b/util/version/version_test.go @@ -34,6 +34,11 @@ func TestGetVersionFromImageName(t *testing.T) { args: args{name: "karolis/webhook-demo:latest"}, wantErr: true, }, + { + name: "image no tag", + args: args{name: "karolis/webhook-demo"}, + wantErr: true, + }, { name: "image webhookrelay", args: args{name: "gcr.io/webhookrelay/webhookrelay:0.1.14"}, From c0a0c102d304d8d3103f3d181230ed91637beb2f Mon Sep 17 00:00:00 2001 From: Karolis Rusenas Date: Sun, 2 Jul 2017 08:47:24 +0100 Subject: [PATCH 2/3] sample updated --- hack/deployment.sample.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/hack/deployment.sample.yml b/hack/deployment.sample.yml index 9e334f23..4133fb61 100644 --- a/hack/deployment.sample.yml +++ b/hack/deployment.sample.yml @@ -17,7 +17,7 @@ spec: app: keel spec: containers: - - image: karolisr/keel:0.2.1 + - image: karolisr/keel:0.2.3 imagePullPolicy: Always env: - name: PUBSUB @@ -33,6 +33,4 @@ spec: path: /healthz port: 9300 initialDelaySeconds: 30 - timeoutSeconds: 10 - securityContext: - privileged: true + timeoutSeconds: 10 From 7812ef37643202b9c9b44c4ba52fceff8a352a5b Mon Sep 17 00:00:00 2001 From: Karolis Rusenas Date: Sun, 2 Jul 2017 09:32:46 +0100 Subject: [PATCH 3/3] providing more info on event process start --- provider/kubernetes/kubernetes.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/provider/kubernetes/kubernetes.go b/provider/kubernetes/kubernetes.go index a012f0fe..b89b7e82 100644 --- a/provider/kubernetes/kubernetes.go +++ b/provider/kubernetes/kubernetes.go @@ -62,6 +62,8 @@ func (p *Provider) startInternal() error { case event := <-p.events: log.WithFields(log.Fields{ "repository": event.Repository.Name, + "tag": event.Repository.Tag, + "registry": event.Repository.Host, }).Info("provider.kubernetes: processing event") _, err := p.processEvent(event) if err != nil {