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

generate clientset as the CRD's SDK #409

Merged
merged 3 commits into from
Mar 25, 2024
Merged
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
1 change: 1 addition & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ ignore:
- "**/*.pb.go"
- "**/*.pb.validate.go"
- '**/zz_generated.deepcopy.go'
- "controller/pkg/client"
6 changes: 6 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ jobs:
echo "Generated files are not up-to-date. Please run 'make gen-proto' and commit changes."
exit 1
fi
cd controller
make gen-crd-code
if ! git diff --exit-code; then
echo "Generated files are not up-to-date. Please run 'make gen-crd-code' and commit changes."
exit 1
fi

- name: lint go
run: make lint-go
Expand Down
14 changes: 14 additions & 0 deletions controller/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

PROJECT_NAME = mosn.io/htnn
# Image URL to use all building/pushing image targets
IMG ?= htnn-controller:latest
# Use distroless as minimal base image to package the manager binary
Expand Down Expand Up @@ -196,3 +197,16 @@ $(ENVTEST): $(LOCALBIN)
.PHONY: start-controller-service
start-controller-service:
cd ./tests/testdata/services && docker-compose up -d

GO_FMTTER_VERSION = 0.3.8
.PHONY: install-go-fmtter
install-go-fmtter: $(LOCALBIN)
if ! test -x $(LOCALBIN)/gosimports || ! $(LOCALBIN)/gosimports -version | grep $(GO_FMTTER_VERSION) >/dev/null; then \
GOBIN=$(LOCALBIN) go install github.com/rinchsan/gosimports/cmd/gosimports@v$(GO_FMTTER_VERSION); \
fi

.PHONY: gen-crd-code
gen-crd-code: $(LOCALBIN) install-go-fmtter
test -s $(LOCALBIN)/client-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/[email protected]
LOCALBIN=$(LOCALBIN) ./hack/gen-crd-code.sh
$(LOCALBIN)/gosimports -w -local ${PROJECT_NAME} ./pkg/client
6 changes: 3 additions & 3 deletions controller/PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ resources:
controller: true
group: mosn.io
kind: HTTPFilterPolicy
path: mosn.io/htnn/controller/api/v1
path: mosn.io/htnn/controller/apis/v1
version: v1
webhooks:
defaulting: true
Expand All @@ -25,7 +25,7 @@ resources:
controller: true
group: mosn.io
kind: Consumer
path: mosn.io/htnn/controller/api/v1
path: mosn.io/htnn/controller/apis/v1
version: v1
webhooks:
defaulting: true
Expand All @@ -37,7 +37,7 @@ resources:
controller: true
group: mosn.io
kind: ServiceRegistry
path: mosn.io/htnn/controller/api/v1
path: mosn.io/htnn/controller/apis/v1
version: v1
webhooks:
defaulting: true
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (s *ConsumerStatus) Reset() {
s.changed = false
}

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

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ var (

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme

// SchemeGroupVersion is group version used to register these objects
// Deprecated: use GroupVersion instead.
// Here we keep it for compatibility with client-gen.
SchemeGroupVersion = GroupVersion
)
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (s *HTTPFilterPolicyStatus) Reset() {
s.changed = false
}

//+genclient
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:metadata:labels=gateway.networking.k8s.io/policy=direct
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type ServiceRegistryStatus struct {
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

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

Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion controller/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"

mosniov1 "mosn.io/htnn/controller/api/v1"
mosniov1 "mosn.io/htnn/controller/apis/v1"
"mosn.io/htnn/controller/internal/config"
"mosn.io/htnn/controller/internal/controller"
"mosn.io/htnn/controller/internal/log"
Expand Down
44 changes: 44 additions & 0 deletions controller/hack/gen-crd-code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
# Copyright The HTNN 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 -euo pipefail

readonly REPO=mosn.io/htnn
readonly OUTPUT_PKG=${REPO}/controller/pkg/client
readonly APIS_PKG=${REPO}/controller
readonly CLIENTSET_NAME=versioned
readonly CLIENTSET_PKG_NAME=clientset
readonly GOPATH="$(mktemp -d)"
readonly SCRIPT_ROOT="$(pwd)"

export GOPATH
mkdir -p "$GOPATH/src/$REPO"
ln -s "${SCRIPT_ROOT}" "$GOPATH/src/$APIS_PKG"

if [[ "${VERIFY_CODEGEN:-}" == "true" ]]; then
echo "Running in verification mode"
readonly VERIFY_FLAG="--verify-only"
fi

readonly COMMON_FLAGS="${VERIFY_FLAG:-} --go-header-file ${SCRIPT_ROOT}/hack/boilerplate.go.txt"

echo "Generating clientset at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME}"
"${LOCALBIN}"/client-gen \
--clientset-name "${CLIENTSET_NAME}" \
--input-base "" \
--input "${APIS_PKG}/apis/v1" \
--output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME}" \
${COMMON_FLAGS}
2 changes: 1 addition & 1 deletion controller/internal/controller/consumer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

mosniov1 "mosn.io/htnn/controller/api/v1"
mosniov1 "mosn.io/htnn/controller/apis/v1"
"mosn.io/htnn/controller/internal/config"
"mosn.io/htnn/controller/internal/istio"
"mosn.io/htnn/controller/internal/model"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import (
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"

mosniov1 "mosn.io/htnn/controller/api/v1"
mosniov1 "mosn.io/htnn/controller/apis/v1"
"mosn.io/htnn/controller/internal/config"
"mosn.io/htnn/controller/internal/metrics"
"mosn.io/htnn/controller/internal/model"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
gwapiv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2"

mosniov1 "mosn.io/htnn/controller/api/v1"
mosniov1 "mosn.io/htnn/controller/apis/v1"
"mosn.io/htnn/controller/tests/pkg"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

mosniov1 "mosn.io/htnn/controller/api/v1"
mosniov1 "mosn.io/htnn/controller/apis/v1"
"mosn.io/htnn/controller/internal/registry"
)

Expand Down
2 changes: 1 addition & 1 deletion controller/internal/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

mosniov1 "mosn.io/htnn/controller/api/v1"
mosniov1 "mosn.io/htnn/controller/apis/v1"
"mosn.io/htnn/controller/internal/log"
pkgRegistry "mosn.io/htnn/controller/pkg/registry"
)
Expand Down
2 changes: 1 addition & 1 deletion controller/internal/translation/init_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"k8s.io/apimachinery/pkg/types"
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"

mosniov1 "mosn.io/htnn/controller/api/v1"
mosniov1 "mosn.io/htnn/controller/apis/v1"
)

type VirtualServicePolicies struct {
Expand Down
2 changes: 1 addition & 1 deletion controller/internal/translation/merged_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"k8s.io/apimachinery/pkg/types"

mosniov1 "mosn.io/htnn/controller/api/v1"
mosniov1 "mosn.io/htnn/controller/apis/v1"
"mosn.io/htnn/controller/internal/model"
"mosn.io/htnn/pkg/filtermanager"
fmModel "mosn.io/htnn/pkg/filtermanager/model"
Expand Down
2 changes: 1 addition & 1 deletion controller/internal/translation/translation.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

"github.com/go-logr/logr"

mosniov1 "mosn.io/htnn/controller/api/v1"
mosniov1 "mosn.io/htnn/controller/apis/v1"
)

type Ctx struct {
Expand Down
2 changes: 1 addition & 1 deletion controller/internal/translation/translation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
gwapiv1 "sigs.k8s.io/gateway-api/apis/v1"
"sigs.k8s.io/yaml"

mosniov1 "mosn.io/htnn/controller/api/v1"
mosniov1 "mosn.io/htnn/controller/apis/v1"
"mosn.io/htnn/controller/internal/istio"
"mosn.io/htnn/controller/tests/pkg"
)
Expand Down
121 changes: 121 additions & 0 deletions controller/pkg/client/clientset/versioned/clientset.go

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

Loading