Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
9347eae
:book: suplememting info about release process
camilamacedo86 Feb 18, 2021
5cc7d55
Add tests to the DNS validation package
Adirio Feb 18, 2021
7a7a66f
Remove old TODOs that are no longer valid
Adirio Feb 22, 2021
615f8c2
Merge pull request #2033 from Adirio/cleanup-todos
k8s-ci-robot Feb 22, 2021
33036c5
Merge pull request #2034 from Adirio/tests/dns-validation
k8s-ci-robot Feb 22, 2021
c45c5da
fix unit tests to work with later versions of ginkgo/gomega
joelanford Feb 25, 2021
ed6539a
Merge pull request #2039 from joelanford/fix/test-unit
k8s-ci-robot Feb 25, 2021
d121077
:seedling: fix CI to use the correct g version
camilamacedo86 Feb 25, 2021
d07dfcc
Merge pull request #2040 from camilamacedo86/fix-ci-go-version
k8s-ci-robot Feb 25, 2021
4bf571c
Explicitly define WithCompletion as an Option
Adirio Feb 26, 2021
cfbf62d
Merge pull request #2045 from Adirio/completion-option
k8s-ci-robot Feb 26, 2021
1586c2d
Generalize CRD and webhook version related methods in Config
Adirio Feb 26, 2021
0610cc8
Merge pull request #2047 from Adirio/config-interface
k8s-ci-robot Feb 26, 2021
64ad95f
:seedling: Update golangci-lint to latest version
Feb 25, 2021
a90cbd5
Merge pull request #2041 from goutamtadi1/update-golangci-lint
k8s-ci-robot Feb 27, 2021
75ac496
Add https to the webpage
mkumatag Mar 1, 2021
80177d3
Merge pull request #2050 from mkumatag/fix_link
k8s-ci-robot Mar 1, 2021
2ef938f
Add go mod tidy to be executed after the scaffolding api
dastergon Feb 24, 2021
2b46403
Merge pull request #2037 from dastergon/fix-api-generation
k8s-ci-robot Mar 1, 2021
1a74c97
docs: update CRD path for multi-group api
ahalimx86 Mar 2, 2021
bc7ce7d
netlify.toml: update redirects for v3.0.0
estroz Mar 4, 2021
d905233
(go/v3) bump controller-runtime to v0.7.2
estroz Mar 5, 2021
f81fb0d
feat: improve service monitor configuration
johanneswuerbach Mar 5, 2021
bdfa597
Use client.New instead of manager client in tests
leovct Mar 6, 2021
984816b
Merge pull request #2062 from estroz/docs/update-redirects
k8s-ci-robot Mar 8, 2021
6de8014
Merge pull request #2054 from ahalim-intel/update_migrations
k8s-ci-robot Mar 8, 2021
2018a4f
Merge pull request #2064 from estroz/deps/bump-c-r-0.7.2
k8s-ci-robot Mar 8, 2021
01293b2
Fix the config registry public API
Adirio Mar 9, 2021
9a121a1
test/e2e: export KIND_CLUSTER so local tests get correct cluster name
estroz Mar 9, 2021
b6e2ead
Merge pull request #2071 from estroz/chore/correct-test-cluster-name
k8s-ci-robot Mar 9, 2021
c748ebd
This commit adds a ServiceAccount (config/rbac/service_account.yaml)
estroz Mar 8, 2021
dd3942c
Merge pull request #2070 from estroz/feature/service-account
k8s-ci-robot Mar 9, 2021
4e6c400
Remove CLI interface and expose cli instead
Adirio Mar 10, 2021
2687774
Move the internal machinery utils to appropiate exported packages
Adirio Mar 9, 2021
8e0f0ab
Merge pull request #2074 from Adirio/export-machinery-utils
k8s-ci-robot Mar 10, 2021
f0ab179
Merge pull request #2072 from Adirio/fix-config-registry-api
k8s-ci-robot Mar 10, 2021
de84b80
Merge pull request #2079 from Adirio/cli-external-api
k8s-ci-robot Mar 10, 2021
0675cd5
Merge pull request #2030 from camilamacedo86/imp-release-docs
k8s-ci-robot Mar 10, 2021
fe73ff7
Add `kubebuilder alpha config-gen` subcommand
pwittrock Mar 7, 2021
9742a11
Merge pull request #1831 from pwittrock/main
k8s-ci-robot Mar 13, 2021
a2cc78c
Inject filesystem from cli instead of creating several per command
Adirio Mar 12, 2021
73cda2b
Merge pull request #2080 from Adirio/inject-filesystem
k8s-ci-robot Mar 13, 2021
61dcae6
Export scaffolding machinery
Adirio Mar 14, 2021
f7ad796
Store abstraction for persisting Config
Adirio Mar 14, 2021
23c49c2
Add fish completion
Adirio Mar 15, 2021
cd8812d
Merge pull request #2083 from Adirio/export-config-machinery
k8s-ci-robot Mar 15, 2021
bca394b
Provide third-party devs the option to provide their own alpha subcom…
Adirio Mar 15, 2021
e9caa6e
Merge pull request #2088 from Adirio/fish-code-completion
k8s-ci-robot Mar 15, 2021
fdb87df
Merge pull request #2089 from Adirio/extra-alpha-commands
k8s-ci-robot Mar 15, 2021
83230ae
Improve plugin phase 1.5 EP
Adirio Mar 9, 2021
6ca3450
Merge pull request #2082 from Adirio/export-scaffold-machinery
k8s-ci-robot Mar 15, 2021
fb4beed
Add coverage badge from Coveralls
Adirio Mar 15, 2021
388b36e
Remove kubebuilder hardcoded reference in alpha subcommand description
Adirio Mar 15, 2021
05be3c2
Fix alpha extra commands parent command
Adirio Mar 15, 2021
94b63e2
Merge pull request #2090 from Adirio/add-coverage-badge
k8s-ci-robot Mar 15, 2021
4b4d28a
Merge pull request #2091 from Adirio/alpha-description
k8s-ci-robot Mar 15, 2021
bebd89c
Merge pull request #2092 from Adirio/fix-alpha-subcommands
k8s-ci-robot Mar 15, 2021
9eb0747
Cleanup help messages
Adirio Mar 16, 2021
104672d
Merge pull request #2093 from Adirio/cleanup-help
k8s-ci-robot Mar 16, 2021
82c1b65
Fix coverage report on master
Adirio Mar 16, 2021
e806ba0
Merge pull request #2094 from Adirio/fix-ci
k8s-ci-robot Mar 16, 2021
e5b6435
Merge pull request #2066 from leovct/use-client-new-in-tests
k8s-ci-robot Mar 16, 2021
911f342
Merge pull request #2075 from Adirio/ep-plugin-phase-1.5
k8s-ci-robot Mar 16, 2021
668b999
Enable the storage of multiple plugins as layout
Adirio Mar 17, 2021
406d79d
Merge pull request #2096 from Adirio/config-chain
estroz Mar 17, 2021
faff148
Merge pull request #2065 from johanneswuerbach/improve-service-monitor
k8s-ci-robot Mar 17, 2021
f7b0ae3
pkg/cli/alpha/config-gen: command docs no longer depend on local envi…
estroz Mar 17, 2021
f2e1edb
Plugin phase 1.5 implementation
Adirio Mar 15, 2021
646f742
Merge pull request #2097 from estroz/docs/config-gen-static-cmd-docs
estroz Mar 18, 2021
2983c97
Merge pull request #2060 from Adirio/plugin-phase-1.5
k8s-ci-robot Mar 18, 2021
62e4812
Fix linting issues
Adirio Mar 22, 2021
b789900
Merge pull request #2102 from Adirio/fix-lint
k8s-ci-robot Mar 23, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add kubebuilder alpha config-gen subcommand
- Add the alpha subcommand
- Add config-gen as an alpha subcommand

config-gen includes controller-gen as a library, and generates configuration for kubebuilder projects.
  • Loading branch information
pwittrock committed Mar 13, 2021
commit fe73ff7b993ec51603b7ba5fd90495716b95f952
21 changes: 21 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
Copyright 2020 The Kubernetes 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.
*/

//go:generate go run github.com/markbates/pkger/cmd/pkger

// Package kubebuilder contains pkged files compiled into the
// go binaries.
package kubebuilder
11 changes: 10 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@ module sigs.k8s.io/kubebuilder/v3
go 1.15

require (
github.com/cloudflare/cfssl v1.5.0 // for `kubebuilder alpha config-gen`
github.com/gobuffalo/flect v0.2.2
// TODO: remove this in favor of embed once using 1.16
github.com/markbates/pkger v0.17.1 // for `kubebuilder alpha config-gen`
github.com/onsi/ginkgo v1.15.0
github.com/onsi/gomega v1.10.5
github.com/spf13/afero v1.2.2
github.com/spf13/cobra v0.0.7
github.com/spf13/cobra v1.1.1
github.com/spf13/pflag v1.0.5
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e
// for `kubebuilder alpha config-gen`
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
k8s.io/apimachinery v0.20.2 // for `kubebuilder alpha config-gen`
k8s.io/utils v0.0.0-20210111153108-fddb29f9d009 // indirect
sigs.k8s.io/controller-tools v0.3.0 // for `kubebuilder alpha config-gen`
sigs.k8s.io/kustomize/kyaml v0.10.10 // for `kubebuilder alpha config-gen`
sigs.k8s.io/yaml v1.2.0
)
561 changes: 552 additions & 9 deletions go.sum

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions pkg/cli/alpha.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Copyright 2021 The Kubernetes 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 cli

import (
"strings"

"github.com/spf13/cobra"
configgen "sigs.k8s.io/kubebuilder/v3/pkg/cli/alpha/config-gen"
)

var alphaCommands = []*cobra.Command{
configgen.NewCommand(),
}

func (c *CLI) newAlphaCmd() *cobra.Command {
alpha := &cobra.Command{
Use: "alpha",
SuggestFor: []string{"experimental"},
Short: "Alpha kubebuilder subcommands",
Long: strings.TrimSpace(`
Alpha kubebuilder commands are for unstable features.
- Alpha commands are exploratory and may be removed without warning.
- No backwards compatibility is provided for any alpha commands.
`),
}
for i := range alphaCommands {
alpha.AddCommand(alphaCommands[i])
}
return alpha
}

func (c *CLI) addAlphaCmd() {
if len(alphaCommands) > 0 {
c.cmd.AddCommand(c.newAlphaCmd())
}
}
41 changes: 41 additions & 0 deletions pkg/cli/alpha/config-gen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Config-gen

`kubebuilder alpha config-gen` is a subcommand that generates configuration for kubebuilder projects as a configuration function.

Supports:

- Generating CRDs and RBAC from code
- Generating webhook certificates for development
- Selectively enabling / disabling components such as prometheus and webhooks
- See [types.go](apis/v1alpha1/types.go) for a list of components

## Usage

`config-gen` may be run as a standalone command or from kustomize as a transformer plugin.

### Standalone command

config-gen may be run as a standalone program on the commandline.

See [examples/standalone](examples/standalone/README.md)

### From kustomize

config-gen may be run as a Kustomize plugin using kustomize.

See [examples/kustomize](examples/kustomize/README.md)

### Extending `config-gen`

config-gen may be extended by composing additional functions on top of it.

See examples of layering additional functions on:

- [examples/basicextension](examples/basicextension/README.md)
- [examples/advancedextension](examples/advancedextension/README.md)

## `KubebuilderConfigGen`

See [types.go](apis/v1alpha1/types.go) for KubebuilderConfigGen schema.

See [testdata](apis/v1alpha1/testdata) for examples of configuration options.
164 changes: 164 additions & 0 deletions pkg/cli/alpha/config-gen/cert-generation-filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/*
Copyright 2021 The Kubernetes 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 configgen

import (
"encoding/base64"
"fmt"

"github.com/cloudflare/cfssl/cli/genkey"
"github.com/cloudflare/cfssl/config"
"github.com/cloudflare/cfssl/csr"
"github.com/cloudflare/cfssl/helpers"
"github.com/cloudflare/cfssl/selfsign"
"sigs.k8s.io/kustomize/kyaml/fn/framework"
"sigs.k8s.io/kustomize/kyaml/kio"
"sigs.k8s.io/kustomize/kyaml/yaml"
)

var _ kio.Filter = &CertFilter{}

// CertFilter generates and injects certificates into webhook
type CertFilter struct {
*KubebuilderConfigGen
}

// Filter implements kio.Filter
func (c CertFilter) Filter(input []*yaml.RNode) ([]*yaml.RNode, error) {

if c.Spec.Webhooks.CertificateSource.Type != "dev" {
return input, nil
}
if err := c.generateCert(); err != nil {
return nil, err
}

s := &framework.Selector{
Kinds: []string{
"ValidatingWebhookConfiguration",
"MutatingWebhookConfiguration",
},
}
matches, err := s.GetMatches(&framework.ResourceList{Items: input})
if err != nil {
return nil, err
}
for i := range matches {
wh := matches[i].Field("webhooks")
if wh.IsNilOrEmpty() {
continue
}
err := wh.Value.VisitElements(func(node *yaml.RNode) error {
err := node.PipeE(yaml.LookupCreate(yaml.ScalarNode, "clientConfig", "caBundle"),
yaml.FieldSetter{StringValue: c.Status.CertCA})
if err != nil {
return err
}
err = node.PipeE(yaml.LookupCreate(yaml.ScalarNode, "clientConfig", "service", "namespace"),
yaml.FieldSetter{StringValue: c.Namespace})
if err != nil {
return err
}

return nil
})
if err != nil {
return nil, err
}
}

s = &framework.Selector{
Filter: func(n *yaml.RNode) bool {
// Allow-list conversion webhooks
m, _ := n.GetMeta()
if m.Kind != "CustomResourceDefinition" {
return true
}
return c.Spec.Webhooks.Conversions[m.Name]
},
}
matches, err = s.GetMatches(&framework.ResourceList{Items: input})
if err != nil {
return nil, err
}
for i := range matches {
err := matches[i].PipeE(yaml.LookupCreate(yaml.ScalarNode, "spec", "conversion", "strategy"),
yaml.FieldSetter{StringValue: "Webhook"})
if err != nil {
return nil, err
}
err = matches[i].PipeE(yaml.LookupCreate(
yaml.ScalarNode, "spec", "conversion", "webhookClientConfig", "caBundle"),
yaml.FieldSetter{StringValue: c.Status.CertCA})
if err != nil {
return nil, err
}
err = matches[i].PipeE(yaml.LookupCreate(
yaml.ScalarNode, "spec", "conversion", "webhookClientConfig", "service", "name"),
yaml.FieldSetter{StringValue: "webhook-service"})
if err != nil {
return nil, err
}
err = matches[i].PipeE(yaml.LookupCreate(
yaml.ScalarNode, "spec", "conversion", "webhookClientConfig", "service", "namespace"),
yaml.FieldSetter{StringValue: c.Namespace})
if err != nil {
return nil, err
}

err = matches[i].PipeE(yaml.LookupCreate(
yaml.ScalarNode, "spec", "conversion", "webhookClientConfig", "service", "path"),
yaml.FieldSetter{StringValue: "/convert"})
if err != nil {
return nil, err
}
}

return input, nil
}

func (c CertFilter) generateCert() error {
var err error
var req = csr.New()
req.Hosts = []string{
fmt.Sprintf("webhook-service.%s.svc", c.Namespace),
fmt.Sprintf("webhook-service.%s.svc.cluster.local", c.Namespace),
}
req.CN = "kb-dev-controller-manager"

var key, csrPEM []byte
g := &csr.Generator{Validator: genkey.Validator}
csrPEM, key, err = g.ProcessRequest(req)
if err != nil {
return err
}
priv, err := helpers.ParsePrivateKeyPEM(key)
if err != nil {
return err
}

profile := config.DefaultConfig()
profile.Expiry = c.Spec.Webhooks.CertificateSource.DevCertificate.CertDuration
cert, err := selfsign.Sign(priv, csrPEM, profile)
if err != nil {
return err
}

c.Status.CertCA = base64.StdEncoding.EncodeToString(cert)
c.Status.CertKey = base64.StdEncoding.EncodeToString(key)
return nil
}
39 changes: 39 additions & 0 deletions pkg/cli/alpha/config-gen/cert-manager-patches.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright 2021 The Kubernetes 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 configgen

import (
"github.com/markbates/pkger"
"sigs.k8s.io/kustomize/kyaml/fn/framework"
)

// CertManagerPatchTemplate returns the PatchTemplate for cert-manager
func CertManagerPatchTemplate(_ *KubebuilderConfigGen) framework.PT {
return framework.PT{
// keep casting -- required by pkger to find the directory
Dir: pkger.Dir("/pkg/cli/alpha/config-gen/templates/patches/cert-manager"),
Selector: func() *framework.Selector {
return &framework.Selector{
Kinds: []string{
"CustomResourceDefinition",
"ValidatingWebhookConfiguration",
"MutatingWebhookConfiguration",
},
}
},
}
}
Loading