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

update golang version and controller-runtime version from alphav1 to v1 #340

Merged
merged 1 commit into from
Feb 27, 2025
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
21 changes: 12 additions & 9 deletions api/disaggregated/v1/disaggregatedcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
package v1

import (
"context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// log is for logging in this package.
Expand All @@ -32,38 +34,39 @@ func (ddc *DorisDisaggregatedCluster) SetupWebhookWithManager(mgr ctrl.Manager)
}

// +kubebuilder:unnamedwatches:path=/mutate-disaggregated-doris-com-v1-dorisdisaggregatedcluster,mutating=true,failurePolicy=ignore,sideEffects=None,groups=disaggregated.cluster.doris.com,resources=dorisdisaggregatedclusters,verbs=create;update;delete,versions=v1,name=mdorisdisaggregatedcluster.kb.io,admissionReviewVersions=v1
var _ webhook.Defaulter = &DorisDisaggregatedCluster{}
var _ webhook.CustomDefaulter = &DorisDisaggregatedCluster{}

// Default implements webhook.Defaulter so a unnamedwatches will be registered for the type
func (ddc *DorisDisaggregatedCluster) Default() {
func (ddc *DorisDisaggregatedCluster) Default(ctx context.Context, obj runtime.Object) error {
klog.Infof("disaggregatedwebhook mutate disaggregated doris cluster name=%s.", ddc.Name)
// TODO(user): fill in your defaulting logic.
return nil
}

// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
// +kubebuilder:unnamedwatches:path=/validate-disaggregated-doris-com-v1-dorisdisaggregatedcluster,mutating=false,failurePolicy=ignore,sideEffects=None,groups=disaggregated.cluster.doris.com,resources=dorisdisaggregatedclusters,verbs=create;update,versions=v1,name=vdorisdisaggregatedcluster.kb.io,admissionReviewVersions=v1
var _ webhook.Validator = &DorisDisaggregatedCluster{}
var _ webhook.CustomValidator = &DorisDisaggregatedCluster{}

// ValidateCreate implements webhook.Validator so a unnamedwatches will be registered for the type
func (ddc *DorisDisaggregatedCluster) ValidateCreate() error {
func (ddc *DorisDisaggregatedCluster) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
klog.Info("validate create", "name", ddc.Name)

// TODO(user): fill in your validation logic upon object creation.
return nil
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a unnamedwatches will be registered for the type
func (ddc *DorisDisaggregatedCluster) ValidateUpdate(old runtime.Object) error {
func (ddc *DorisDisaggregatedCluster) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
klog.Info("validate update", "name", ddc.Name)

// TODO(user): fill in your validation logic upon object update.
return nil
return nil, nil
}

// ValidateDelete implements webhook.Validator so a unnamedwatches will be registered for the type
func (ddc *DorisDisaggregatedCluster) ValidateDelete() error {
func (ddc *DorisDisaggregatedCluster) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
klog.Info("validate delete", "name", ddc.Name)

// TODO(user): fill in your validation logic upon object deletion.
return nil
return nil, nil
}
23 changes: 13 additions & 10 deletions api/doris/v1/doriscluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ limitations under the License.
package v1

import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/runtime"
kerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/klog/v2"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
)

// log is for logging in this package.
Expand All @@ -51,29 +53,30 @@ func (r *DorisCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
}

// +kubebuilder:unnamedwatches:path=/mutate-doris-selectdb-com-v1-doriscluster,mutating=true,failurePolicy=ignore,sideEffects=None,groups=doris.selectdb.com,resources=dorisclusters,verbs=create;update;delete,versions=v1,name=mdoriscluster.kb.io,admissionReviewVersions=v1
var _ webhook.Defaulter = &DorisCluster{}
var _ webhook.CustomDefaulter = &DorisCluster{}

// Default implements webhook.Defaulter so a unnamedwatches will be registered for the type
func (r *DorisCluster) Default() {
func (r *DorisCluster) Default(ctx context.Context, obj runtime.Object) error {
klog.Infof("mutatingwebhook mutate doriscluster name=%s.", r.Name)
// TODO(user): fill in your defaulting logic.
return nil
}

// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
//+kubebuilder:unnamedwatches:path=/validate-doris-selectdb-com-v1-doriscluster,mutating=false,failurePolicy=fail,sideEffects=None,groups=doris.selectdb.com,resources=dorisclusters,verbs=create;update,versions=v1,name=vdoriscluster.kb.io,admissionReviewVersions=v1

var _ webhook.Validator = &DorisCluster{}
var _ webhook.CustomValidator = &DorisCluster{}

// ValidateCreate implements webhook.Validator so a unnamedwatches will be registered for the type
func (r *DorisCluster) ValidateCreate() error {
func (r *DorisCluster) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
klog.Info("validate create", "name", r.Name)

// TODO(user): fill in your validation logic upon object creation.
return nil
return nil, nil
}

// ValidateUpdate implements webhook.Validator so a unnamedwatches will be registered for the type
func (r *DorisCluster) ValidateUpdate(old runtime.Object) error {
func (r *DorisCluster) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
klog.Info("validate update", "name", r.Name)
var errors []error
// fe FeSpec.Replicas must greater than or equal to FeSpec.ElectionNumber
Expand All @@ -82,16 +85,16 @@ func (r *DorisCluster) ValidateUpdate(old runtime.Object) error {
}

if len(errors) != 0 {
return kerrors.NewAggregate(errors)
return nil, kerrors.NewAggregate(errors)
}

return nil
return nil, nil
}

// ValidateDelete implements webhook.Validator so a unnamedwatches will be registered for the type
func (r *DorisCluster) ValidateDelete() error {
func (r *DorisCluster) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
klog.Info("validate delete", "name", r.Name)

// TODO(user): fill in your validation logic upon object deletion.
return nil
return nil, nil
}
19 changes: 12 additions & 7 deletions api/doris/v1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
// specific language governing permissions and limitations
// under the License.


package v1

import (
Expand All @@ -24,6 +23,8 @@ import (
"fmt"
"net"
"path/filepath"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"testing"
"time"

Expand Down Expand Up @@ -92,12 +93,16 @@ var _ = BeforeSuite(func() {
// start unnamedwatches server using Manager
webhookInstallOptions := &testEnv.WebhookInstallOptions
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme,
Host: webhookInstallOptions.LocalServingHost,
Port: webhookInstallOptions.LocalServingPort,
CertDir: webhookInstallOptions.LocalServingCertDir,
LeaderElection: false,
MetricsBindAddress: "0",
Scheme: scheme,
WebhookServer: webhook.NewServer(webhook.Options{
Port: webhookInstallOptions.LocalServingPort,
Host: webhookInstallOptions.LocalServingHost,
CertDir: webhookInstallOptions.LocalServingCertDir,
}),
LeaderElection: false,
Metrics: metricsserver.Options{
BindAddress: "0",
},
})
Expect(err).NotTo(HaveOccurred())

Expand Down
40 changes: 30 additions & 10 deletions cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ limitations under the License.
package main

import (
"context"
"fmt"
dv1 "github.com/apache/doris-operator/api/disaggregated/v1"
dorisv1 "github.com/apache/doris-operator/api/doris/v1"
Expand All @@ -46,7 +47,10 @@ import (
"k8s.io/utils/pointer"
"os"
"path/filepath"
"sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/cache"
controllerconfig "sigs.k8s.io/controller-runtime/pkg/config"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"time"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
Expand Down Expand Up @@ -110,16 +114,28 @@ func main() {
printVersionInfos(f.PrintVar)

ctrl.SetLogger(zap.New(zap.UseFlagOptions(&f.Opts)))
webhookServer := webhook.NewServer(webhook.Options{
Port: 9443,
})
defaultNamespaces := map[string]cache.Config{}
if f.Namespace != "" {
defaultNamespaces[f.Namespace] = cache.Config{}
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: f.MetricsAddr,
Port: 9443,
Scheme: scheme,
Metrics: metricsserver.Options{
BindAddress: f.MetricsAddr,
},
HealthProbeBindAddress: f.ProbeAddr,
Namespace: f.Namespace,
LeaderElection: f.EnableLeaderElection,
LeaderElectionID: "e1370669.selectdb.com",
Cache: cache.Options{
DefaultNamespaces: defaultNamespaces,
},
WebhookServer: webhookServer,
LeaderElection: f.EnableLeaderElection,
LeaderElectionID: "e1370669.selectdb.com",
//if one reconcile failed, others will not be affected.
Controller: v1alpha1.ControllerConfigurationSpec{
Controller: controllerconfig.Controller{
RecoverPanic: pointer.Bool(true),
},

Expand Down Expand Up @@ -159,8 +175,12 @@ func main() {
//wait for the secret have
interval := time.Second * 1
timeout := time.Second * 30
keyPath := filepath.Join(mgr.GetWebhookServer().CertDir, certificate.TLsCertName)
err = wait.PollImmediate(interval, timeout, func() (bool, error) {
fctx := context.Background()
err = wait.PollUntilContextTimeout(fctx, interval, timeout, true, func(ctx context.Context) (bool, error) {
srv := webhookServer.(*webhook.DefaultServer)
//when default server start in mgr.start, the option will add default values. so, certDir if not set, default values will be "<temp-dir>/k8s-webhook-server/serving-certs."
certDir := srv.Options.CertDir
keyPath := filepath.Join(certDir, certificate.TLsCertName)
_, err := os.Stat(keyPath)
if os.IsNotExist(err) {
setupLog.Info("webhook certificate have not present waiting kubelet update", "file", keyPath)
Expand Down
Loading