Skip to content

Commit

Permalink
Add apply gen to controller-tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Jefftree committed Nov 30, 2022
1 parent 3aeb037 commit 2332681
Show file tree
Hide file tree
Showing 15 changed files with 1,786 additions and 195 deletions.
7 changes: 6 additions & 1 deletion cmd/controller-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,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)
}
}
Loading

0 comments on commit 2332681

Please sign in to comment.