Skip to content

Commit

Permalink
ci: add hack/generate-client.sh and generate client code (#229)
Browse files Browse the repository at this point in the history
* ci: add generate-client.sh and generate client code

* ci: add make check-client-generation

* ci: fix lint errors

* ci: add check-client-generation ci

* ci(docker): use go:1.23

* refactor: download kube_codegen.sh from upstream

* ci: don't review pkg/client/** for coderabbit

* refactor: refine the generate-client.sh
  • Loading branch information
zyy17 authored Dec 4, 2024
1 parent 97540bd commit 84856f2
Show file tree
Hide file tree
Showing 51 changed files with 2,669 additions and 110 deletions.
1 change: 1 addition & 0 deletions .coderabbit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ reviews:
- "!config/**"
- "!examples/**"
- "!docs/**"
- "!pkg/client/**"
auto_review:
enabled: true
drafts: true
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/develop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ jobs:
run: |
make check-code-generation
- name: Check client generation
shell: bash
run: |
make check-client-generation
- name: Compile the project
shell: bash
run: |
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ generate: kustomize controller-gen ## Generate code containing DeepCopy, DeepCop
fmt: ## Run go fmt against code.
go fmt ./...

.PHONY: generate-client
generate-client: ## Generate the pkg/client/{clientset,informers,listers} code.
./hack/client/generate-client.sh

.PHONY: check-code-generation
check-code-generation: ## Check code generation.
echo "Checking code generation"
Expand Down Expand Up @@ -121,6 +125,12 @@ check-api-docs: api-docs ## Check docs
(echo "Need to update documentation, please run 'make api-docs'"; \
exit 1)

.PHONY: check-client-generation
check-client-generation: generate-client ## Check client generation.
@git diff --quiet || \
(echo "Need to update client code, please run 'make generate-client'"; \
exit 1)

.PHONY: kind-up
kind-up: ## Create the kind cluster for developing.
./hack/kind/3-nodes-with-local-registry.sh
Expand Down
20 changes: 10 additions & 10 deletions apis/v1alpha1/defaulting.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"
)

// SetDefaults sets the default values for the GreptimeDBCluster.
Expand Down Expand Up @@ -163,7 +163,7 @@ func (in *GreptimeDBCluster) defaultFrontend() *FrontendSpec {
return &FrontendSpec{
ComponentSpec: ComponentSpec{
Template: &PodTemplateSpec{},
Replicas: pointer.Int32(DefaultReplicas),
Replicas: ptr.To(int32(DefaultReplicas)),
Logging: &LoggingSpec{},
},
RPCPort: DefaultRPCPort,
Expand All @@ -185,7 +185,7 @@ func (in *GreptimeDBCluster) defaultMeta() *MetaSpec {
return &MetaSpec{
ComponentSpec: ComponentSpec{
Template: &PodTemplateSpec{},
Replicas: pointer.Int32(DefaultReplicas),
Replicas: ptr.To(int32(DefaultReplicas)),
Logging: &LoggingSpec{},
},
RPCPort: DefaultMetaRPCPort,
Expand All @@ -199,7 +199,7 @@ func (in *GreptimeDBCluster) defaultDatanode() *DatanodeSpec {
return &DatanodeSpec{
ComponentSpec: ComponentSpec{
Template: &PodTemplateSpec{},
Replicas: pointer.Int32(DefaultReplicas),
Replicas: ptr.To(int32(DefaultReplicas)),
Logging: &LoggingSpec{},
},
RPCPort: DefaultRPCPort,
Expand All @@ -213,7 +213,7 @@ func (in *GreptimeDBCluster) defaultFlownodeSpec() *FlownodeSpec {
return &FlownodeSpec{
ComponentSpec: ComponentSpec{
Template: &PodTemplateSpec{},
Replicas: pointer.Int32(DefaultReplicas),
Replicas: ptr.To(int32(DefaultReplicas)),
Logging: &LoggingSpec{},
},
RPCPort: DefaultRPCPort,
Expand Down Expand Up @@ -345,8 +345,8 @@ func (in *GreptimeDBStandalone) defaultSpec() *GreptimeDBStandaloneSpec {
Level: DefaultLoggingLevel,
LogsDir: DefaultLogsDir,
Format: LogFormatText,
PersistentWithData: pointer.Bool(false),
OnlyLogToStdout: pointer.Bool(false),
PersistentWithData: ptr.To(false),
OnlyLogToStdout: ptr.To(false),
},
DatanodeStorage: defaultDatanodeStorage(),
RollingUpdate: defaultRollingUpdateForStatefulSet(),
Expand All @@ -372,8 +372,8 @@ func defaultLogging() *LoggingSpec {
Level: DefaultLoggingLevel,
LogsDir: DefaultLogsDir,
Format: LogFormatText,
PersistentWithData: pointer.Bool(false),
OnlyLogToStdout: pointer.Bool(false),
PersistentWithData: ptr.To(false),
OnlyLogToStdout: ptr.To(false),
}
}

Expand Down Expand Up @@ -445,7 +445,7 @@ func defaultRollingUpdateForDeployment() *appsv1.RollingUpdateDeployment {
// Same as the default rolling update strategy of StatefulSet.
func defaultRollingUpdateForStatefulSet() *appsv1.RollingUpdateStatefulSetStrategy {
return &appsv1.RollingUpdateStatefulSetStrategy{
Partition: pointer.Int32(0),
Partition: ptr.To(int32(0)),
MaxUnavailable: &intstr.IntOrString{
Type: intstr.Int,
IntVal: 1,
Expand Down
1 change: 1 addition & 0 deletions apis/v1alpha1/greptimedbcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ func (in *GreptimeDBClusterStatus) SetCondition(condition Condition) {
in.Conditions = SetCondition(in.Conditions, condition)
}

// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:shortName=gtc
Expand Down
1 change: 1 addition & 0 deletions apis/v1alpha1/greptimedbstandalone_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ type GreptimeDBStandaloneStatus struct {
ObservedGeneration *int64 `json:"observedGeneration,omitempty"`
}

// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:shortName=gts
Expand Down
7 changes: 7 additions & 0 deletions apis/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "greptime.io", Version: "v1alpha1"}

SchemeGroupVersion = GroupVersion

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

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

// Resource is required by pkg/client/listers/...
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
10 changes: 5 additions & 5 deletions cmd/initializer/internal/config_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"strings"

"k8s.io/klog/v2"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

"github.com/GreptimeTeam/greptimedb-operator/apis/v1alpha1"
"github.com/GreptimeTeam/greptimedb-operator/pkg/dbconfig"
Expand Down Expand Up @@ -114,14 +114,14 @@ func (c *ConfigGenerator) generateDatanodeConfig(initConfig []byte) ([]byte, err
if len(podIP) == 0 {
return nil, fmt.Errorf("empty pod ip")
}
datanodeCfg.RPCAddr = pointer.String(fmt.Sprintf("%s:%d", podIP, c.DatanodeRPCPort))
datanodeCfg.RPCAddr = ptr.To(fmt.Sprintf("%s:%d", podIP, c.DatanodeRPCPort))

podName := os.Getenv(deployer.EnvPodName)
if len(podName) == 0 {
return nil, fmt.Errorf("empty pod name")
}

datanodeCfg.RPCHostName = pointer.String(fmt.Sprintf("%s.%s.%s:%d", podName,
datanodeCfg.RPCHostName = ptr.To(fmt.Sprintf("%s.%s.%s:%d", podName,
c.DatanodeServiceName, c.Namespace, c.DatanodeRPCPort))

configData, err := dbconfig.Marshal(cfg)
Expand Down Expand Up @@ -157,14 +157,14 @@ func (c *ConfigGenerator) generateFlownodeConfig(initConfig []byte) ([]byte, err
if len(podIP) == 0 {
return nil, fmt.Errorf("empty pod ip")
}
flownodeCfg.Addr = pointer.String(fmt.Sprintf("%s:%d", podIP, c.RPCPort))
flownodeCfg.Addr = ptr.To(fmt.Sprintf("%s:%d", podIP, c.RPCPort))

podName := os.Getenv(deployer.EnvPodName)
if len(podName) == 0 {
return nil, fmt.Errorf("empty pod name")
}

flownodeCfg.Hostname = pointer.String(fmt.Sprintf("%s.%s.%s:%d", podName,
flownodeCfg.Hostname = ptr.To(fmt.Sprintf("%s.%s.%s:%d", podName,
c.ServiceName, c.Namespace, c.RPCPort))

configData, err := dbconfig.Marshal(cfg)
Expand Down
4 changes: 2 additions & 2 deletions cmd/operator/app/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/klog/v2"
"k8s.io/klog/v2/klogr"
"k8s.io/klog/v2/textlogger"
podmetricsv1beta1 "k8s.io/metrics/pkg/apis/metrics/v1beta1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
Expand Down Expand Up @@ -73,7 +73,7 @@ func NewOperatorCommand() *cobra.Command {
Use: "greptimedb-operator",
Short: "greptimedb-operator manages GreptimeDB clusters atop Kubernetes.",
Run: func(cmd *cobra.Command, args []string) {
ctrl.SetLogger(klogr.New())
ctrl.SetLogger(textlogger.NewLogger(textlogger.NewConfig()))
setupLog := ctrl.Log.WithName("setup")
cfg := ctrl.GetConfigOrDie()

Expand Down
Loading

0 comments on commit 84856f2

Please sign in to comment.