Skip to content

Commit 66de9e4

Browse files
authored
Merge pull request #70 from Dyanngg/generate-clients
Add generated clientset, informers and listers
2 parents c233253 + 354de2d commit 66de9e4

36 files changed

+2348
-234
lines changed

Makefile

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,61 @@ help: ## Display this help.
2323

2424
##@ Development
2525

26+
CLIENTSET_NAME ?= versioned
27+
CLIENTSET_PKG_NAME ?= clientset
28+
API_PKG ?= sigs.k8s.io/network-policy-api
29+
API_GROUP_NAME ?= policy.networking.k8s.io
30+
API_DIR ?= ${API_PKG}/apis/v1alpha1
31+
OUTPUT_PKG ?= sigs.k8s.io/network-policy-api/client
32+
COMMON_FLAGS ?= --go-header-file $(shell pwd)/hack/boilerplate.go.txt
33+
34+
.PHONY: manifests
2635
manifests: ## Generate ClusterRole and CustomResourceDefinition objects.
2736
go run sigs.k8s.io/controller-tools/cmd/controller-gen rbac:roleName=manager-role crd paths=./apis/... output:crd:dir=./config/crd/bases output:stdout
2837

29-
generate: ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
30-
go run sigs.k8s.io/controller-tools/cmd/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
31-
38+
.PHONY: fmt
3239
fmt: ## Run go fmt against code.
3340
go fmt ./...
3441

42+
.PHONY: vet
3543
vet: ## Run go vet against code.
3644
go vet ./...
3745

46+
.PHONY: generate
47+
generate: generate-deepcopy generate-typed-clients generate-typed-listers generate-typed-informers
48+
49+
.PHONY: generate-deepcopy
50+
generate-deepcopy: ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
51+
go run sigs.k8s.io/controller-tools/cmd/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
52+
53+
.PHONY: generate-typed-clients
54+
generate-typed-clients: ## Generate typed client code
55+
go run k8s.io/code-generator/cmd/client-gen \
56+
--clientset-name "${CLIENTSET_NAME}" \
57+
--input-base "" \
58+
--input "${API_DIR}" \
59+
--output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME}" \
60+
${COMMON_FLAGS}
61+
62+
.PHONY: generate-typed-listers
63+
generate-typed-listers: ## Generate typed listers code
64+
go run k8s.io/code-generator/cmd/lister-gen \
65+
--input-dirs "${API_DIR}" \
66+
--output-package "${OUTPUT_PKG}/listers" \
67+
${COMMON_FLAGS}
68+
69+
.PHONY: generate-typed-informers
70+
generate-typed-informers: ## Generate typed informers code
71+
go run k8s.io/code-generator/cmd/informer-gen \
72+
--input-dirs "${API_DIR}" \
73+
--versioned-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME}/${CLIENTSET_NAME}" \
74+
--listers-package "${OUTPUT_PKG}/listers" \
75+
--output-package "${OUTPUT_PKG}/informers" \
76+
${COMMON_FLAGS}
77+
3878
all: generate manifests fmt vet ## Runs all the development targets
3979

80+
.PHONY: verify
4081
verify:
4182
hack/verify-all.sh -v
4283

apis/v1alpha1/adminnetworkpolicy_types.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ import (
2323
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2424
)
2525

26-
//+kubebuilder:object:root=true
27-
//+kubebuilder:subresource:status
28-
//+kubebuilder:resource:scope=Cluster
26+
// +genclient
27+
// +kubebuilder:object:root=true
28+
// +kubebuilder:subresource:status
29+
// +kubebuilder:resource:scope=Cluster
30+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
2931

3032
// AdminNetworkPolicy is a cluster level resource that is part of the
3133
// AdminNetworkPolicy API.
@@ -176,15 +178,12 @@ const (
176178
AdminNetworkPolicyRuleActionPass AdminNetworkPolicyRuleAction = "Pass"
177179
)
178180

179-
//+kubebuilder:object:root=true
181+
// +kubebuilder:object:root=true
182+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
180183

181184
// AdminNetworkPolicyList contains a list of AdminNetworkPolicy
182185
type AdminNetworkPolicyList struct {
183186
metav1.TypeMeta `json:",inline"`
184187
metav1.ListMeta `json:"metadata,omitempty"`
185188
Items []AdminNetworkPolicy `json:"items"`
186189
}
187-
188-
func init() {
189-
SchemeBuilder.Register(&AdminNetworkPolicy{}, &AdminNetworkPolicyList{})
190-
}

apis/v1alpha1/baselineadminnetworkpolicy_types.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ import (
1919
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2020
)
2121

22-
//+kubebuilder:object:root=true
23-
//+kubebuilder:subresource:status
24-
//+kubebuilder:resource:scope=Cluster
22+
// +genclient
23+
// +kubebuilder:object:root=true
24+
// +kubebuilder:subresource:status
25+
// +kubebuilder:resource:scope=Cluster
26+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
2527

2628
// BaselineAdminNetworkPolicy is a cluster level resource that is part of the
2729
// AdminNetworkPolicy API.
@@ -98,7 +100,7 @@ type BaselineAdminNetworkPolicyIngressRule struct {
98100
Ports *[]AdminNetworkPolicyPort `json:"ports,omitempty"`
99101
}
100102

101-
// AdminNetworkPolicyEgressRule describes an action to take on a particular
103+
// BaselineAdminNetworkPolicyEgressRule describes an action to take on a particular
102104
// set of traffic originating from pods selected by a BaselineAdminNetworkPolicy's
103105
// Subject field.
104106
type BaselineAdminNetworkPolicyEgressRule struct {
@@ -142,15 +144,12 @@ const (
142144
BaselineAdminNetworkPolicyRuleActionAllow BaselineAdminNetworkPolicyRuleAction = "Allow"
143145
)
144146

145-
//+kubebuilder:object:root=true
147+
// +kubebuilder:object:root=true
148+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
146149

147150
// BaselineAdminNetworkPolicyList contains a list of BaselineAdminNetworkPolicy
148151
type BaselineAdminNetworkPolicyList struct {
149152
metav1.TypeMeta `json:",inline"`
150153
metav1.ListMeta `json:"metadata,omitempty"`
151154
Items []BaselineAdminNetworkPolicy `json:"items"`
152155
}
153-
154-
func init() {
155-
SchemeBuilder.Register(&BaselineAdminNetworkPolicy{}, &BaselineAdminNetworkPolicyList{})
156-
}

apis/v1alpha1/register.go

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
Copyright 2022.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/apimachinery/pkg/runtime"
22+
"k8s.io/apimachinery/pkg/runtime/schema"
23+
)
24+
25+
var (
26+
// SchemeGroupVersion is group version used to register these objects
27+
SchemeGroupVersion = schema.GroupVersion{Group: "policy.networking.k8s.io", Version: "v1alpha1"}
28+
29+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
30+
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
31+
32+
// AddToScheme adds the types in this group-version to the given scheme.
33+
AddToScheme = SchemeBuilder.AddToScheme
34+
)
35+
36+
func init() {
37+
// We only register manually written functions here. The registration of the
38+
// generated functions takes place in the generated files. The separation
39+
// makes the code compile even when the generated files are missing.
40+
SchemeBuilder.Register(addKnownTypes)
41+
}
42+
43+
// Resource takes an unqualified resource and returns a Group qualified GroupResource
44+
func Resource(resource string) schema.GroupResource {
45+
return SchemeGroupVersion.WithResource(resource).GroupResource()
46+
}
47+
48+
// Adds the list of known types to the given scheme.
49+
func addKnownTypes(scheme *runtime.Scheme) error {
50+
scheme.AddKnownTypes(
51+
SchemeGroupVersion,
52+
&AdminNetworkPolicy{},
53+
&AdminNetworkPolicyList{},
54+
&BaselineAdminNetworkPolicy{},
55+
&BaselineAdminNetworkPolicyList{},
56+
)
57+
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
58+
return nil
59+
}

apis/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/golangci-lint

25.3 MB
Binary file not shown.

client/clientset/versioned/clientset.go

Lines changed: 120 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/clientset/versioned/doc.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)