Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Generation of typed apply clients #536

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 8 additions & 1 deletion cmd/controller-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/spf13/cobra"

"sigs.k8s.io/controller-tools/pkg/applyconfigurations"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jefftree,

The only thing that needs to be added is tests. So, could you please add them?
Also, could you please track 2 issues in the repo:

a) For we address the TODO: https://github.com/kubernetes-sigs/controller-tools/pull/536/files#r1022245967
b) To check further if there is anything else we could replace here in a follow-up to use the upstream implementations instead of re-implement them?

"sigs.k8s.io/controller-tools/pkg/crd"
"sigs.k8s.io/controller-tools/pkg/deepcopy"
"sigs.k8s.io/controller-tools/pkg/genall"
Expand Down Expand Up @@ -51,6 +52,7 @@ var (
"crd": crd.Generator{},
"rbac": rbac.Generator{},
"object": deepcopy.Generator{},
"apply": applyconfigurations.Generator{},
Jefftree marked this conversation as resolved.
Show resolved Hide resolved
"webhook": webhook.Generator{},
"schemapatch": schemapatcher.Generator{},
}
Expand Down Expand Up @@ -139,13 +141,18 @@ func main() {
controller-gen object paths=./apis/v1beta1/some_types.go

# Generate OpenAPI v3 schemas for API packages and merge them into existing CRD manifests
controller-gen schemapatch:manifests=./manifests output:dir=./manifests paths=./pkg/apis/...
controller-gen schemapatch:manifests=./manifests output:dir=./manifests paths=./pkg/apis/...

# Run all the generators for a given project
controller-gen paths=./apis/...

# Explain the markers for generating CRDs, and their arguments
controller-gen crd -ww

# Generate applyconfigurations for CRDs for use with Server Side Apply. They will be placed
# into a "ac/" subdirectory

controller-gen apply paths=./apis/...
`,
RunE: func(c *cobra.Command, rawOpts []string) error {
// print version if asked for it
Expand Down
41 changes: 41 additions & 0 deletions pkg/applyconfigurations/codewriter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
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 applyconfigurations

import (
"fmt"
"io"
)

// codeWriter assists in writing out Go code lines and blocks to a writer.
type codeWriter struct {
out io.Writer
}

// Line writes a single line.
func (c *codeWriter) Line(line string) {
if _, err := fmt.Fprintln(c.out, line); err != nil {
panic(err)
}
}

// Linef writes a single line with formatting (as per fmt.Sprintf).
func (c *codeWriter) Linef(line string, args ...interface{}) {
if _, err := fmt.Fprintf(c.out, line+"\n", args...); err != nil {
panic(err)
}
}
18 changes: 18 additions & 0 deletions pkg/applyconfigurations/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
Copyright 2019 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 applyconfigurations generates types for constructing declarative apply configurations.
package applyconfigurations
Loading