From 2668bdb81a069b8fad27bf3a237b97eb34e4f3ba Mon Sep 17 00:00:00 2001 From: Matthias Wessendorf Date: Tue, 15 Oct 2019 18:13:32 +0200 Subject: [PATCH] Adding common sourceLabels func (#720) * Adding common sourceLabels func * fixing feedback from @mattmoor * fixing typo --- OWNERS_ALIASES | 4 ++++ source/OWNERS | 4 ++++ source/doc.go | 18 +++++++++++++++++ source/source_labels.go | 29 +++++++++++++++++++++++++++ source/source_labels_test.go | 38 ++++++++++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+) create mode 100644 source/OWNERS create mode 100644 source/doc.go create mode 100644 source/source_labels.go create mode 100644 source/source_labels_test.go diff --git a/OWNERS_ALIASES b/OWNERS_ALIASES index 7821e95ee..52cfdb2bd 100644 --- a/OWNERS_ALIASES +++ b/OWNERS_ALIASES @@ -62,6 +62,10 @@ aliases: - steuhs - yt3liu + source-approvers: + - n3wscott + - vaikas-google + webhook-approvers: - mattmoor - grantr diff --git a/source/OWNERS b/source/OWNERS new file mode 100644 index 000000000..8d1691216 --- /dev/null +++ b/source/OWNERS @@ -0,0 +1,4 @@ +# The OWNERS file is used by prow to automatically merge approved PRs. + +approvers: +- source-approvers diff --git a/source/doc.go b/source/doc.go new file mode 100644 index 000000000..fc827c38a --- /dev/null +++ b/source/doc.go @@ -0,0 +1,18 @@ +/* +Copyright 2019 The Knative Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Package source holds utilities for Source developers. +package source diff --git a/source/source_labels.go b/source/source_labels.go new file mode 100644 index 000000000..f669bad69 --- /dev/null +++ b/source/source_labels.go @@ -0,0 +1,29 @@ +/* + * Copyright 2019 The Knative Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package source + +const ( + sourceControllerName = "sources.knative.dev/controller" + sourceName = "sources.knative.dev/name" +) + +func Labels(name, controllerAgentName string) map[string]string { + return map[string]string{ + sourceControllerName: controllerAgentName, + sourceName: name, + } +} diff --git a/source/source_labels_test.go b/source/source_labels_test.go new file mode 100644 index 000000000..459be96c3 --- /dev/null +++ b/source/source_labels_test.go @@ -0,0 +1,38 @@ +/* + * Copyright 2019 The Knative Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package source + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestLabels(t *testing.T) { + + sourceLabeles := Labels("foo", "foo-source-controller") + + wantTags := map[string]string{ + sourceControllerName: "foo-source-controller", + sourceName: "foo", + } + + eq := cmp.Equal(sourceLabeles, wantTags) + if !eq { + t.Fatalf("%v is not equal to %v", sourceLabeles, wantTags) + } +}