Skip to content

Commit

Permalink
fix: workload missing labels and reopen podoverrides (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
whg517 authored Jul 26, 2024
1 parent e79d472 commit ca5a886
Show file tree
Hide file tree
Showing 14 changed files with 28,742 additions and 4,088 deletions.
4 changes: 2 additions & 2 deletions api/v1alpha1/master_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ type MasterRoleGroupSpec struct {
// +kubebuilder:validation:Optional
EnvOverrides map[string]string `json:"envOverrides,omitempty"`

// // +kubebuilder:validation:Optional
// PodOverride *corev1.PodTemplateSpec `json:"podOverride,omitempty"`
// +kubebuilder:validation:Optional
PodOverrides *corev1.PodTemplateSpec `json:"podOverrides,omitempty"`
}
4 changes: 2 additions & 2 deletions api/v1alpha1/regionserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ type RegionServerRoleGroupSpec struct {
// +kubebuilder:validation:Optional
EnvOverrides map[string]string `json:"envOverrides,omitempty"`

// // +kubebuilder:validation:Optional
// PodOverride *corev1.PodTemplateSpec `json:"podOverride,omitempty"`
// +kubebuilder:validation:Optional
PodOverrides *corev1.PodTemplateSpec `json:"podOverrides,omitempty"`
}
4 changes: 2 additions & 2 deletions api/v1alpha1/restserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ type RestServerRoleGroupSpec struct {
// +kubebuilder:validation:Optional
EnvOverrides map[string]string `json:"envOverrides,omitempty"`

// // +kubebuilder:validation:Optional
// PodOverride *corev1.PodTemplateSpec `json:"podOverride,omitempty"`
// +kubebuilder:validation:Optional
PodOverrides *corev1.PodTemplateSpec `json:"podOverrides,omitempty"`
}
15 changes: 15 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

32,675 changes: 28,609 additions & 4,066 deletions config/crd/bases/hbase.zncdata.dev_hbaseclusters.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion config/manager/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
images:
- name: controller
newName: quay.io/zncdata/hbase-operator
newName: quay.io/zncdatadev/hbase-operator
newTag: v0.0.1
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ spec:
- name: hbase
url: https://hbase.apache.org/
maintainers:
- email: zncdatadev@googlegroups.com
name: ZNCDataDev Team
- email: zncdatadev@googlegroups.com
name: ZNCDataDev Team
maturity: stable
minKubeVersion: 1.26.1
provider:
Expand Down
3 changes: 1 addition & 2 deletions internal/controller/common/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ func NewStatefulSetBuilder(
replicas *int32,
ports []corev1.ContainerPort,
image *util.Image,
options *builder.WorkloadOptions,
) *StatefulSetBuilder {

options := &builder.WorkloadOptions{}

return &StatefulSetBuilder{
StatefulSet: *builder.NewStatefulSetBuilder(client, name, replicas, image, options),
Ports: ports,
Expand Down
6 changes: 5 additions & 1 deletion internal/controller/master/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (r *Reconciler) RegisterResourceWithRoleGroup(_ context.Context, info recon

var reconcilers []reconciler.Reconciler

statefulSetReconciler := NewStatefulSetReconciler(
statefulSetReconciler, err := NewStatefulSetReconciler(
r.Client,
r.ClusterConfig,
info,
Expand All @@ -82,6 +82,10 @@ func (r *Reconciler) RegisterResourceWithRoleGroup(_ context.Context, info recon
roleGroupSpec.(*hbasev1alph1.MasterRoleGroupSpec),
)

if err != nil {
return nil, err
}

reconcilers = append(reconcilers, statefulSetReconciler)

serviceReconciler := common.NewServiceReconciler(
Expand Down
33 changes: 31 additions & 2 deletions internal/controller/master/statefulset.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package master

import (
"time"

hbasev1alph1 "github.com/zncdatadev/hbase-operator/api/v1alpha1"
"github.com/zncdatadev/hbase-operator/internal/controller/common"
"github.com/zncdatadev/operator-go/pkg/builder"
Expand All @@ -17,7 +19,33 @@ func NewStatefulSetReconciler(
ports []corev1.ContainerPort,
image *util.Image,
spec *hbasev1alph1.MasterRoleGroupSpec,
) reconciler.ResourceReconciler[builder.StatefulSetBuilder] {
) (reconciler.ResourceReconciler[builder.StatefulSetBuilder], error) {

options := &builder.WorkloadOptions{
Labels: roleGroupInfo.GetLabels(),
Annotations: roleGroupInfo.GetAnnotations(),
PodOverrides: spec.PodOverrides,
CommandOverrides: spec.CommandOverrides,
EnvOverrides: spec.EnvOverrides,
}

if spec.Config != nil {

var gracefulShutdownTimeout time.Duration
var err error

if spec.Config.GracefulShutdownTimeout != nil {
gracefulShutdownTimeout, err = time.ParseDuration(*spec.Config.GracefulShutdownTimeout)
if err != nil {
return nil, err
}
}

options.TerminationGracePeriod = &gracefulShutdownTimeout
options.Resource = spec.Config.Resources
options.Affinity = spec.Config.Affinity
}

stsBuilder := common.NewStatefulSetBuilder(
client,
roleGroupInfo.GetFullName(),
Expand All @@ -30,11 +58,12 @@ func NewStatefulSetReconciler(
spec.Replicas,
ports,
image,
options,
)

return reconciler.NewStatefulSet(
client,
roleGroupInfo.GetFullName(),
stsBuilder,
)
), nil
}
8 changes: 6 additions & 2 deletions internal/controller/regionserver/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewReconciler(
clusterOperation,
spec,
),
Image: image,
Image: image,
ClusterConfig: clusterConfig,
}
}
Expand Down Expand Up @@ -72,7 +72,7 @@ func (r *Reconciler) RegisterResourceWithRoleGroup(_ context.Context, info recon

var reconcilers []reconciler.Reconciler

statefulSetReconciler := NewStatefulSetReconciler(
statefulSetReconciler, err := NewStatefulSetReconciler(
r.Client,
r.ClusterConfig,
info,
Expand All @@ -81,6 +81,10 @@ func (r *Reconciler) RegisterResourceWithRoleGroup(_ context.Context, info recon
roleGroupSpec.(*hbasev1alph1.RegionServerRoleGroupSpec),
)

if err != nil {
return nil, err
}

reconcilers = append(reconcilers, statefulSetReconciler)

serviceReconciler := common.NewServiceReconciler(
Expand Down
32 changes: 30 additions & 2 deletions internal/controller/regionserver/statefulset.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package regionserver

import (
"time"

hbasev1alph1 "github.com/zncdatadev/hbase-operator/api/v1alpha1"
"github.com/zncdatadev/hbase-operator/internal/controller/common"
"github.com/zncdatadev/operator-go/pkg/builder"
Expand All @@ -17,7 +19,32 @@ func NewStatefulSetReconciler(
ports []corev1.ContainerPort,
image *util.Image,
spec *hbasev1alph1.RegionServerRoleGroupSpec,
) reconciler.ResourceReconciler[builder.StatefulSetBuilder] {
) (reconciler.ResourceReconciler[builder.StatefulSetBuilder], error) {

options := &builder.WorkloadOptions{
Labels: roleGroupInfo.GetLabels(),
Annotations: roleGroupInfo.GetAnnotations(),
PodOverrides: spec.PodOverrides,
CommandOverrides: spec.CommandOverrides,
EnvOverrides: spec.EnvOverrides,
}

if spec.Config != nil {
var gracefulShutdownTimeout time.Duration
var err error

if spec.Config.GracefulShutdownTimeout != nil {
gracefulShutdownTimeout, err = time.ParseDuration(*spec.Config.GracefulShutdownTimeout)
if err != nil {
return nil, err
}
}

options.TerminationGracePeriod = &gracefulShutdownTimeout
options.Resource = spec.Config.Resources
options.Affinity = spec.Config.Affinity
}

stsBuilder := common.NewStatefulSetBuilder(
client,
roleGroupInfo.GetFullName(),
Expand All @@ -30,6 +57,7 @@ func NewStatefulSetReconciler(
spec.Replicas,
ports,
image,
options,
)

affinityBuilder := stsBuilder.GetDefaultAffinityBuilder()
Expand All @@ -50,5 +78,5 @@ func NewStatefulSetReconciler(
client,
roleGroupInfo.GetFullName(),
stsBuilder,
)
), nil
}
8 changes: 6 additions & 2 deletions internal/controller/restserver/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewReconciler(
clusterOperation,
spec,
),
Image: image,
Image: image,
ClusterConfig: clusterConfig,
}
}
Expand Down Expand Up @@ -72,7 +72,7 @@ func (r *Reconciler) RegisterResourceWithRoleGroup(_ context.Context, info recon

var reconcilers []reconciler.Reconciler

statefulSetReconciler := NewStatefulSetReconciler(
statefulSetReconciler, err := NewStatefulSetReconciler(
r.Client,
r.ClusterConfig,
info,
Expand All @@ -81,6 +81,10 @@ func (r *Reconciler) RegisterResourceWithRoleGroup(_ context.Context, info recon
roleGroupSpec.(*hbasev1alph1.RestServerRoleGroupSpec),
)

if err != nil {
return nil, err
}

reconcilers = append(reconcilers, statefulSetReconciler)

serviceReconciler := common.NewServiceReconciler(
Expand Down
32 changes: 30 additions & 2 deletions internal/controller/restserver/statefulset.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package restserver

import (
"time"

hbasev1alph1 "github.com/zncdatadev/hbase-operator/api/v1alpha1"
"github.com/zncdatadev/hbase-operator/internal/controller/common"
"github.com/zncdatadev/operator-go/pkg/builder"
Expand All @@ -17,7 +19,32 @@ func NewStatefulSetReconciler(
ports []corev1.ContainerPort,
image *util.Image,
spec *hbasev1alph1.RestServerRoleGroupSpec,
) reconciler.ResourceReconciler[builder.StatefulSetBuilder] {
) (reconciler.ResourceReconciler[builder.StatefulSetBuilder], error) {

options := &builder.WorkloadOptions{
Labels: roleGroupInfo.GetLabels(),
Annotations: roleGroupInfo.GetAnnotations(),
PodOverrides: spec.PodOverrides,
CommandOverrides: spec.CommandOverrides,
EnvOverrides: spec.EnvOverrides,
}

if spec.Config != nil {
var gracefulShutdownTimeout time.Duration
var err error

if spec.Config.GracefulShutdownTimeout != nil {
gracefulShutdownTimeout, err = time.ParseDuration(*spec.Config.GracefulShutdownTimeout)
if err != nil {
return nil, err
}
}

options.TerminationGracePeriod = &gracefulShutdownTimeout
options.Resource = spec.Config.Resources
options.Affinity = spec.Config.Affinity
}

stsBuilder := common.NewStatefulSetBuilder(
client,
roleGroupInfo.GetFullName(),
Expand All @@ -30,11 +57,12 @@ func NewStatefulSetReconciler(
spec.Replicas,
ports,
image,
options,
)

return reconciler.NewStatefulSet(
client,
roleGroupInfo.GetFullName(),
stsBuilder,
)
), nil
}

0 comments on commit ca5a886

Please sign in to comment.