Skip to content

Commit 7efdc4b

Browse files
committed
add functoin set-standard-labels
1 parent f361a33 commit 7efdc4b

File tree

18 files changed

+611
-0
lines changed

18 files changed

+611
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
4+
// https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/
5+
const (
6+
AppLabelPrefix = "app.kubernetes.io/"
7+
AppName = AppLabelPrefix + "name"
8+
AppInstance = AppLabelPrefix + "instance"
9+
10+
// TBD
11+
AppVersion = AppLabelPrefix + "version"
12+
AppComponent = AppLabelPrefix + "component"
13+
AppPartOf = AppLabelPrefix + "part-of"
14+
AppManagedBy = AppLabelPrefix + "managed-by"
15+
)
16+
17+
const (
18+
PackageContextKind = "ConfigMap"
19+
PackageContextName = "kptfile.kpt.dev"
20+
)
21+
22+
23+
const (
24+
SetLabelFnKind = "ConfigMap"
25+
SetLabelFnName = "recommended-labels"
26+
)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module github.com/GoogleContainerTools/kpt-functions-catalog/functions/go/set-standard-labels
2+
3+
go 1.19
4+
5+
require (
6+
github.com/GoogleContainerTools/kpt-functions-catalog/functions/go/set-labels v0.0.0-20221018012752-f361a33ec921
7+
github.com/GoogleContainerTools/kpt-functions-sdk/go/fn v0.0.0-20221018174030-e63010a12b00
8+
k8s.io/apimachinery v0.25.3
9+
)
10+
11+
require (
12+
github.com/GoogleContainerTools/kpt-functions-sdk/go/api v0.0.0-20221018174030-e63010a12b00 // indirect
13+
github.com/davecgh/go-spew v1.1.1 // indirect
14+
github.com/go-errors/errors v1.4.2 // indirect
15+
github.com/go-logr/logr v1.2.3 // indirect
16+
github.com/go-openapi/jsonpointer v0.19.5 // indirect
17+
github.com/go-openapi/jsonreference v0.20.0 // indirect
18+
github.com/go-openapi/swag v0.22.3 // indirect
19+
github.com/gogo/protobuf v1.3.2 // indirect
20+
github.com/golang/protobuf v1.5.2 // indirect
21+
github.com/google/gnostic v0.6.9 // indirect
22+
github.com/google/go-cmp v0.5.9 // indirect
23+
github.com/google/gofuzz v1.2.0 // indirect
24+
github.com/josharian/intern v1.0.0 // indirect
25+
github.com/mailru/easyjson v0.7.7 // indirect
26+
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
27+
github.com/xlab/treeprint v1.1.0 // indirect
28+
golang.org/x/sys v0.1.0 // indirect
29+
google.golang.org/protobuf v1.28.1 // indirect
30+
gopkg.in/yaml.v2 v2.4.0 // indirect
31+
gopkg.in/yaml.v3 v3.0.1 // indirect
32+
k8s.io/klog/v2 v2.80.1 // indirect
33+
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
34+
sigs.k8s.io/kustomize/kyaml v0.13.9 // indirect
35+
)

functions/go/set-standard-labels/go.sum

Lines changed: 221 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2022 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
package main
15+
16+
import (
17+
"context"
18+
"testing"
19+
20+
"github.com/GoogleContainerTools/kpt-functions-sdk/go/fn"
21+
"github.com/GoogleContainerTools/kpt-functions-sdk/go/fn/testhelpers"
22+
)
23+
24+
const TestDataPath = "testdata"
25+
26+
27+
func TestFunction(t *testing.T) {
28+
// Read the `testdata/source` YAML krm resources
29+
fnRunner := fn.WithContext(context.TODO(), &SetStandardLabels{})
30+
testhelpers.RunGoldenTests(t, TestDataPath, fnRunner)
31+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"os"
6+
7+
"github.com/GoogleContainerTools/kpt-functions-sdk/go/fn"
8+
)
9+
10+
func main() {
11+
runner := fn.WithContext(context.Background(), &SetStandardLabels{})
12+
if err := fn.AsMain(runner); err != nil {
13+
os.Exit(1)
14+
}
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: kpt.dev/v1
2+
kind: Kptfile
3+
metadata:
4+
name: base-app
5+
annotations:
6+
config.kubernetes.io/local-config: "true"
7+
info:
8+
description: sample description
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This test is a blueprint package. It expects the label "app.kubernetes.io/name" is added using the package name "base-app"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apiVersion: config.kubernetes.io/v1
2+
kind: ResourceList
3+
items:
4+
- apiVersion: apps/v1
5+
kind: Deployment
6+
metadata:
7+
name: base-app
8+
namespace: example
9+
labels:
10+
app.kubernetes.io/name: base-app
11+
spec:
12+
selector:
13+
matchLabels:
14+
test: abstract-base-app
15+
app.kubernetes.io/name: base-app
16+
template:
17+
metadata:
18+
labels:
19+
test: abstract-base-app
20+
app.kubernetes.io/name: base-app
21+
- apiVersion: kpt.dev/v1
22+
kind: Kptfile
23+
metadata:
24+
name: base-app
25+
annotations:
26+
config.kubernetes.io/local-config: "true"
27+
info:
28+
description: sample description
29+
results:
30+
- message: '`FunctionConfig` is not given'
31+
severity: info
32+
- message: set 3 labels in total
33+
severity: info
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: base-app
6+
namespace: example
7+
spec:
8+
selector:
9+
matchLabels:
10+
test: abstract-base-app
11+
template:
12+
metadata:
13+
labels:
14+
test: abstract-base-app
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: kpt.dev/v1
2+
kind: Kptfile
3+
metadata:
4+
name: frontend
5+
annotations:
6+
config.kubernetes.io/local-config: "true"
7+
info:
8+
description: sample description

0 commit comments

Comments
 (0)