Skip to content

Commit

Permalink
Merge pull request #192 from Jefftree/defaulter
Browse files Browse the repository at this point in the history
Update defaulter-gen to support +default annotation
  • Loading branch information
k8s-ci-robot committed Nov 13, 2020
2 parents 4e0d56a + 7ef7bd7 commit 83324d8
Show file tree
Hide file tree
Showing 10 changed files with 881 additions and 14 deletions.
16 changes: 13 additions & 3 deletions examples/defaulter-gen/Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
TOOL=defaulter-gen

.PHONY : gen test verify git_verify_clean git_verify_no_change
test:
go test ./_output_tests/marker/...

gen:
@go build -o /tmp/$(TOOL)
@PKGS=$$(cd _output_tests; go list ./... | paste -sd' ' -); \
/tmp/$(TOOL) --logtostderr --v=4 -i $$(echo $$PKGS | sed 's/ /,/g') -O zz_generated

git_verify_clean:
@if ! git diff --quiet HEAD; then \
echo "FAIL: git client is not clean"; \
false; \
fi
@go build -o /tmp/$(TOOL)
@PKGS=$$(cd _output_tests; go list ./... | paste -sd' ' -); \
/tmp/$(TOOL) --logtostderr --v=4 -i $$(echo $$PKGS | sed 's/ /,/g') -O zz_generated

git_verify_no_change:
@if ! git diff --quiet HEAD; then \
echo "FAIL: output files changed"; \
git diff; \
false; \
fi

verify: git_verify_clean gen git_verify_no_change
31 changes: 31 additions & 0 deletions examples/defaulter-gen/_output_tests/marker/defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
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.
*/

package marker

import (
"k8s.io/apimachinery/pkg/runtime"
)

func addDefaultingFuncs(scheme *runtime.Scheme) error {
return RegisterDefaults(scheme)
}

func SetDefaults_DefaultedWithFunction(obj *DefaultedWithFunction) {
if obj.S1 == "" {
obj.S1 = "default_function"
}
}
20 changes: 20 additions & 0 deletions examples/defaulter-gen/_output_tests/marker/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
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.
*/

// +k8s:defaulter-gen=TypeMeta

// This is a test package.
package marker // import "k8s.io/gengo/examples/defaulter-gen/_output_tests/marker"
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
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.
*/

package marker

import (
runtime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
)

func (in *Defaulted) DeepCopy() *Defaulted {
if in == nil {
return nil
}
out := new(Defaulted)
in.DeepCopyInto(out)
return out
}

func (in *Defaulted) DeepCopyInto(out *Defaulted) {
*out = *in
return
}

func (in *Defaulted) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}

func (in *DefaultedWithFunction) DeepCopy() *DefaultedWithFunction {
if in == nil {
return nil
}
out := new(DefaultedWithFunction)
in.DeepCopyInto(out)
return out
}

func (in *DefaultedWithFunction) DeepCopyInto(out *DefaultedWithFunction) {
*out = *in
return
}

func (in *DefaultedWithFunction) DeepCopyObject() runtime.Object {
if c := in.DeepCopy(); c != nil {
return c
}
return nil
}

func (obj *Defaulted) GetObjectKind() schema.ObjectKind { return schema.EmptyObjectKind }
func (obj *DefaultedWithFunction) GetObjectKind() schema.ObjectKind { return schema.EmptyObjectKind }
Loading

0 comments on commit 83324d8

Please sign in to comment.