Skip to content

Commit

Permalink
add client generate codes (#2)
Browse files Browse the repository at this point in the history
add `// +genclient` mark so we can use *-gen tools to
generate client codes automatically.

Signed-off-by: Lan Luo <[email protected]>
  • Loading branch information
luolanzone committed Sep 10, 2021
1 parent c21d88a commit 906463c
Show file tree
Hide file tree
Showing 58 changed files with 4,800 additions and 0 deletions.
3 changes: 3 additions & 0 deletions multicluster/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
$(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/[email protected])

codegen:
./hack/update-codegen.sh

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
WellKnownClusterClaimClusterSet = "clusterSet.k8s.io"
)

// +genclient
//+kubebuilder:object:root=true

// ClusterClaim is the Schema for the clusterclaims API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ type ClusterSetStatus struct {
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

// +genclient
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

Expand Down
5 changes: 5 additions & 0 deletions multicluster/apis/multicluster/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// +k8s:deepcopy-gen=package

// Package v1 is the v1alpha1 version of the API.
// +groupName=multicluster.crd.antrea.io
package v1alpha1
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// +genclient
//+kubebuilder:object:root=true

// MemberClusterAnnounce is the Schema for the memberclusterannounces API
Expand Down
13 changes: 13 additions & 0 deletions multicluster/apis/multicluster/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package v1alpha1

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

// SchemeGroupVersion is group version used to register these objects.
var SchemeGroupVersion = GroupVersion

// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type ResourceExportStatus struct {
Conditions []ResourceExportCondition `json:"conditions,omitempty"`
}

// +genclient
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type ResourceExportFilterStatus struct {
// TBD
}

// +genclient
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ type ResourceImportStatus struct {
ClusterStatuses []ResourceImportClusterStatus `json:"clusterStatuses,omitempty"`
}

// +genclient
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type ResourceImportFilterStatus struct {
// TBD.
}

// +genclient
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

Expand Down
53 changes: 53 additions & 0 deletions multicluster/hack/update-codegen-dockerized.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash

# Copyright 2021 Antrea 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.

set -o errexit
set -o nounset
set -o pipefail

GOPATH=`go env GOPATH`
ANTREA_PKG="antrea.io/antrea"

cd multicluster
rm -rf pkg/client/{clientset,informers,listers}

$GOPATH/bin/client-gen \
--clientset-name versioned \
--input-base "${ANTREA_PKG}/multicluster/apis" \
--input "multicluster/v1alpha1" \
--output-package "${ANTREA_PKG}/multicluster/pkg/client/clientset" \
--go-header-file hack/boilerplate.go.txt

# Generate listers with K8s codegen tools.
$GOPATH/bin/lister-gen \
--input-dirs "${ANTREA_PKG}/multicluster/apis/multicluster/v1alpha1" \
--output-package "${ANTREA_PKG}/multicluster/pkg/client/listers" \
--go-header-file hack/boilerplate.go.txt


# Generate informers with K8s codegen tools.
$GOPATH/bin/informer-gen \
--input-dirs "${ANTREA_PKG}/multicluster/apis/multicluster/v1alpha1" \
--versioned-clientset-package "${ANTREA_PKG}/multicluster/pkg/client/clientset/versioned" \
--listers-package "${ANTREA_PKG}/multicluster/pkg/client/listers" \
--output-package "${ANTREA_PKG}/multicluster/pkg/client/informers" \
--go-header-file hack/boilerplate.go.txt

$GOPATH/bin/deepcopy-gen \
--input-dirs "${ANTREA_PKG}/multicluster/apis/multicluster/v1alpha1" \
-O zz_generated.deepcopy \
--go-header-file hack/boilerplate.go.txt

32 changes: 32 additions & 0 deletions multicluster/hack/update-codegen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

# Copyright 2021 Antrea 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.

set -o errexit
set -o nounset
set -o pipefail

ANTREA_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../../" && pwd )"
IMAGE_NAME="antrea/codegen:kubernetes-1.21.0"

function docker_run() {
docker pull ${IMAGE_NAME}
docker run --rm \
-w /go/src/antrea.io/antrea \
-v ${ANTREA_ROOT}:/go/src/antrea.io/antrea \
"${IMAGE_NAME}" "$@"
}

docker_run multicluster/hack/update-codegen-dockerized.sh
96 changes: 96 additions & 0 deletions multicluster/pkg/client/clientset/versioned/clientset.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions multicluster/pkg/client/clientset/versioned/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions multicluster/pkg/client/clientset/versioned/fake/doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 906463c

Please sign in to comment.