Skip to content

Commit eae0461

Browse files
committed
Add short flags and usage to gatekeeper function.
Also add a release workflow for pushing to gcr.
1 parent 0af3996 commit eae0461

File tree

11 files changed

+58
-249
lines changed

11 files changed

+58
-249
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: release-gatekeeper-function
2+
3+
on:
4+
push:
5+
tags:
6+
- release-gatekeeper-function-*
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
env:
12+
GOPATH: /home/runner/work/kpt-functions-sdk/go
13+
GO111MODULE: off
14+
steps:
15+
- name: Set up gcloud
16+
uses: GoogleCloudPlatform/github-actions/setup-gcloud@master
17+
with:
18+
version: '275.0.0'
19+
service_account_email: ${{ secrets.GCP_SA_EMAIL }}
20+
service_account_key: ${{ secrets.GCP_SA_KEY }}
21+
- name: Set up Go 1.13
22+
uses: actions/setup-go@v1
23+
with:
24+
go-version: 1.13
25+
id: go
26+
- name: Check out code into GOPATH
27+
uses: actions/checkout@v1
28+
with:
29+
path: go/src/github.com/${{ github.repository }}
30+
- name: Build, Test, Lint
31+
run: |
32+
cd go
33+
make all
34+
- name: Push to container registry
35+
run: |
36+
cd go
37+
TAG=latest ./scripts/publish-functions.sh

go/Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ test-e2e:
2424
vet:
2525
go vet ./...
2626

27-
publish-functions: all
28-
./scripts/publish-functions.sh
29-
3027
build-typegen: fix fmt test lint
3128
env GOOS=linux GOARCH=amd64 go build -o $(OUT_DIR)/linux/typegen ./cmd/typegen
3229
env GOOS=darwin GOARCH=amd64 go build -o $(OUT_DIR)/darwin/typegen ./cmd/typegen

go/cmd/gatekeeper_validate/gatekeeper_validate.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ import (
1919
"github.com/GoogleContainerTools/kpt-functions-sdk/go/pkg/functions/gatekeeper"
2020
)
2121

22+
const usage = `
23+
Evaluates OPA constraints against input configuration objects.
24+
25+
Constraints themselves are also declared as part of the input.
26+
`
27+
2228
func main() {
23-
runners.RunFunc(gatekeeper.Validate)
29+
runners.RunFunc(gatekeeper.Validate, usage)
2430
}

go/cmd/require_namespace_label/require_namespace_label.go

Lines changed: 0 additions & 24 deletions
This file was deleted.

go/cmd/require_namespace_label/testing/missing_label.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

go/pkg/framework/runners/runners.go

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,59 +22,42 @@ import (
2222
"github.com/spf13/cobra"
2323
)
2424

25-
const (
26-
inputFlag = "input"
27-
outputFlag = "output"
28-
jsonFlag = "json"
29-
)
30-
3125
var (
3226
input string
3327
output string
3428
useJSON bool
3529
)
3630

3731
func addInputFlag(cmd *cobra.Command) {
38-
cmd.Flags().StringVar(&input, inputFlag, io.Stdin,
39-
`Path to the input JSON file`)
32+
cmd.Flags().StringVarP(&input, "input", "i", io.Stdin,
33+
`path to the input JSON file`)
4034
}
4135

4236
func addOutputFlag(cmd *cobra.Command) {
43-
cmd.Flags().StringVar(&output, outputFlag, io.Stdout,
44-
`Path to the output JSON file`)
37+
cmd.Flags().StringVarP(&output, "output", "o", io.Stdout,
38+
`path to the output JSON file`)
4539
}
4640

4741
func addFormatFlag(cmd *cobra.Command) {
48-
cmd.Flags().BoolVar(&useJSON, jsonFlag, false,
42+
cmd.Flags().BoolVar(&useJSON, "json", false,
4943
`input and output is JSON instead of YAML`)
5044
}
5145

52-
func addProps(cmd *cobra.Command, propNames []string) types.Props {
53-
props := types.Props{}
54-
for _, propName := range propNames {
55-
empty := ""
56-
props[propName] = &empty
57-
cmd.Flags().StringVar(props[propName], propName, "", "")
58-
}
59-
return props
60-
}
61-
6246
func getFormat() io.Format {
6347
if useJSON {
6448
return io.JSON
6549
}
6650
return io.YAML
6751
}
6852

69-
// RunFunc runs a ConfigFunc with the specified property names.
70-
func RunFunc(f types.ConfigFunc, propNames ...string) {
71-
cmd := &cobra.Command{}
53+
// RunFunc runs a ConfigFunc.
54+
func RunFunc(f types.ConfigFunc, usage string) {
55+
cmd := &cobra.Command{Long: usage}
7256
//TODO(b/138231979): Make text output match more closely with go vs typescript.
7357

7458
addInputFlag(cmd)
7559
addOutputFlag(cmd)
7660
addFormatFlag(cmd)
77-
props := addProps(cmd, propNames)
7861

7962
cmd.RunE = func(cmd *cobra.Command, args []string) error {
8063
// Since printing the usage message since we know all required fields are present.
@@ -85,7 +68,7 @@ func RunFunc(f types.ConfigFunc, propNames ...string) {
8568
return err
8669
}
8770

88-
err = f(&configs, props)
71+
err = f(&configs)
8972
if err != nil {
9073
return err
9174
}

go/pkg/framework/types/types.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,8 @@ type KubernetesObject interface {
2929
// functions.
3030
type Configs []KubernetesObject
3131

32-
//TODO(b/138233382): Write Source/Sink funcs and runners.
33-
3432
// ConfigFunc is a type of kpt function that consumes Configs and potentially mutates it.
35-
type ConfigFunc func(configs *Configs, props Props) error
36-
37-
// Props is a collection of properties to configure kpt functions.
38-
type Props map[string]*string
33+
type ConfigFunc func(configs *Configs) error
3934

4035
// ConfigError represents a non-exceptional issue with configuration.
4136
//

go/pkg/functions/gatekeeper/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func gatherConstraints(configs *types.Configs) ([]types.KubernetesObject, error)
8686

8787
// Validate makes sure the configs passed to it comply with any Constraints and
8888
// Constraint Templates present in the list of configs
89-
func Validate(configs *types.Configs, _ types.Props) error {
89+
func Validate(configs *types.Configs) error {
9090
client, err := createClient()
9191
if err != nil {
9292
return err

go/pkg/functions/require_namespace_label/require_namespace_label.go

Lines changed: 0 additions & 59 deletions
This file was deleted.

go/pkg/functions/require_namespace_label/require_namespace_label_test.go

Lines changed: 0 additions & 110 deletions
This file was deleted.

0 commit comments

Comments
 (0)