Skip to content

Commit

Permalink
Fix bump error
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangpengcheng committed Apr 26, 2024
1 parent 1763dae commit 343379e
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 68 deletions.
10 changes: 4 additions & 6 deletions controllers/function_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ import (
"time"

"github.com/streamnative/function-mesh/pkg/monitoring"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/source"

v1 "k8s.io/api/batch/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/handler"

"github.com/go-logr/logr"
"github.com/streamnative/function-mesh/api/compute/v1alpha1"
Expand Down Expand Up @@ -188,8 +186,8 @@ func (r *FunctionReconciler) SetupWithManager(mgr ctrl.Manager) error {
Owns(&corev1.Secret{}).
Owns(&v1.Job{})

manager.Watches(&source.Kind{Type: &v1alpha1.BackendConfig{}}, handler.EnqueueRequestsFromMapFunc(
func(object client.Object) []reconcile.Request {
manager.Watches(&v1alpha1.BackendConfig{}, handler.EnqueueRequestsFromMapFunc(
func(ctx context.Context, object client.Object) []reconcile.Request {
if object.GetName() == utils.GlobalBackendConfig && object.GetNamespace() == utils.GlobalBackendConfigNamespace {
ctx := context.Background()
functions := &v1alpha1.FunctionList{}
Expand Down
10 changes: 4 additions & 6 deletions controllers/sink_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ import (
"time"

"github.com/streamnative/function-mesh/pkg/monitoring"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/source"

v1 "k8s.io/api/batch/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/handler"

"github.com/go-logr/logr"
"github.com/streamnative/function-mesh/api/compute/v1alpha1"
Expand Down Expand Up @@ -193,8 +191,8 @@ func (r *SinkReconciler) SetupWithManager(mgr ctrl.Manager) error {
AddControllerBuilderOwn(manager, r.GroupVersionFlags.APIAutoscalingGroupVersion)
}

manager.Watches(&source.Kind{Type: &v1alpha1.BackendConfig{}}, handler.EnqueueRequestsFromMapFunc(
func(object client.Object) []reconcile.Request {
manager.Watches(&v1alpha1.BackendConfig{}, handler.EnqueueRequestsFromMapFunc(
func(ctx context.Context, object client.Object) []reconcile.Request {
if object.GetName() == utils.GlobalBackendConfig && object.GetNamespace() == utils.GlobalBackendConfigNamespace {
ctx := context.Background()
sinks := &v1alpha1.SinkList{}
Expand Down
13 changes: 5 additions & 8 deletions controllers/source_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,23 @@ import (
"context"
"time"

"github.com/streamnative/function-mesh/pkg/monitoring"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/handler"
k8ssource "sigs.k8s.io/controller-runtime/pkg/source"

"github.com/go-logr/logr"
"github.com/streamnative/function-mesh/api/compute/v1alpha1"
"github.com/streamnative/function-mesh/controllers/spec"
"github.com/streamnative/function-mesh/pkg/monitoring"
"github.com/streamnative/function-mesh/utils"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
vpav1 "k8s.io/autoscaler/vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1"
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)
Expand Down Expand Up @@ -191,10 +189,9 @@ func (r *SourceReconciler) SetupWithManager(mgr ctrl.Manager) error {
if r.GroupVersionFlags != nil && r.GroupVersionFlags.APIAutoscalingGroupVersion != "" {
AddControllerBuilderOwn(manager, r.GroupVersionFlags.APIAutoscalingGroupVersion)
}
manager.Watches(&k8ssource.Kind{Type: &v1alpha1.BackendConfig{}}, handler.EnqueueRequestsFromMapFunc(
func(object client.Object) []reconcile.Request {
manager.Watches(&v1alpha1.BackendConfig{}, handler.EnqueueRequestsFromMapFunc(
func(ctx context.Context, object client.Object) []reconcile.Request {
if object.GetName() == utils.GlobalBackendConfig && object.GetNamespace() == utils.GlobalBackendConfigNamespace {
ctx := context.Background()
sources := &v1alpha1.SourceList{}
err := mgr.GetClient().List(ctx, sources)
if err != nil {
Expand Down
7 changes: 5 additions & 2 deletions controllers/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/envtest"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
// +kubebuilder:scaffold:imports
)

Expand Down Expand Up @@ -80,8 +81,10 @@ var _ = BeforeSuite(func(done Done) {
// +kubebuilder:scaffold:scheme

k8sManager, err := ctrl.NewManager(cfg, ctrl.Options{
Scheme: scheme.Scheme,
MetricsBindAddress: ":8090",
Scheme: scheme.Scheme,
Metrics: server.Options{
BindAddress: ":8090",
},
})
Expect(err).ToNot(HaveOccurred())

Expand Down
32 changes: 25 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import (
"strconv"

"github.com/streamnative/function-mesh/pkg/monitoring"
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/metrics/server"

"github.com/go-logr/logr"
computev1alpha1 "github.com/streamnative/function-mesh/api/compute/v1alpha1"
Expand All @@ -43,6 +45,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
runtimeWebhook "sigs.k8s.io/controller-runtime/pkg/webhook"
// +kubebuilder:scaffold:imports
)

Expand Down Expand Up @@ -130,17 +133,32 @@ func main() {
}
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
options := ctrl.Options{
Scheme: scheme,
Metrics: server.Options{
BindAddress: metricsAddr,
},
HealthProbeBindAddress: healthProbeAddr,
Port: 9443,
LeaderElection: enableLeaderElection,
LeaderElectionNamespace: leaderElectionNamespace,
LeaderElectionID: leaderElectionID,
Namespace: watchedNamespace,
CertDir: certDir,
})
}
if watchedNamespace != "" {
options.Cache = cache.Options{
DefaultNamespaces: map[string]cache.Config{
watchedNamespace: {},
},
}
}
if certDir != "" {
options.WebhookServer = &runtimeWebhook.DefaultServer{
Options: runtimeWebhook.Options{
Port: 9443,
CertDir: certDir,
},
}
}
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), options)
if err != nil {
setupLog.Error(err, "unable to start manager")
os.Exit(1)
Expand Down
26 changes: 13 additions & 13 deletions pkg/webhook/function_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ func (webhook *FunctionWebhook) Default(ctx context.Context, obj runtime.Object)
var _ admission.CustomValidator = &FunctionWebhook{}

// ValidateCreate implements admission.CustomValidator so a webhook will be registered for the type
func (webhook *FunctionWebhook) ValidateCreate(ctx context.Context, obj runtime.Object) error {
func (webhook *FunctionWebhook) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
req, err := admission.RequestFromContext(ctx)
if err != nil {
return fmt.Errorf("expected admission.Request in ctx: %w", err)
return nil, fmt.Errorf("expected admission.Request in ctx: %w", err)
}
if req.Kind.Kind != functionKind {
return fmt.Errorf("expected Kind %q got %q", functionKind, req.Kind.Kind)
return nil, fmt.Errorf("expected Kind %q got %q", functionKind, req.Kind.Kind)
}

r := obj.(*v1alpha1.Function) //nolint:ifshort
Expand Down Expand Up @@ -316,42 +316,42 @@ func (webhook *FunctionWebhook) ValidateCreate(ctx context.Context, obj runtime.
}

if len(allErrs) == 0 {
return nil
return nil, nil
}

return apierrors.NewInvalid(schema.GroupKind{Group: "compute.functionmesh.io", Kind: "FunctionWebhook"}, r.Name, allErrs)
return nil, apierrors.NewInvalid(schema.GroupKind{Group: "compute.functionmesh.io", Kind: "FunctionWebhook"}, r.Name, allErrs)
}

// ValidateUpdate implements admission.CustomValidator so a webhook will be registered for the type
func (webhook *FunctionWebhook) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) error {
func (webhook *FunctionWebhook) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
req, err := admission.RequestFromContext(ctx)
if err != nil {
return fmt.Errorf("expected admission.Request in ctx: %w", err)
return nil, fmt.Errorf("expected admission.Request in ctx: %w", err)
}
if req.Kind.Kind != functionKind {
return fmt.Errorf("expected Kind %q got %q", functionKind, req.Kind.Kind)
return nil, fmt.Errorf("expected Kind %q got %q", functionKind, req.Kind.Kind)
}

r := oldObj.(*v1alpha1.Function) //nolint:ifshort
functionlog.Info("validate update", "name", r.Name)

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

// ValidateDelete implements admission.CustomValidator so a webhook will be registered for the type
func (webhook *FunctionWebhook) ValidateDelete(ctx context.Context, obj runtime.Object) error {
func (webhook *FunctionWebhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
req, err := admission.RequestFromContext(ctx)
if err != nil {
return fmt.Errorf("expected admission.Request in ctx: %w", err)
return nil, fmt.Errorf("expected admission.Request in ctx: %w", err)
}
if req.Kind.Kind != functionKind {
return fmt.Errorf("expected Kind %q got %q", functionKind, req.Kind.Kind)
return nil, fmt.Errorf("expected Kind %q got %q", functionKind, req.Kind.Kind)
}

r := obj.(*v1alpha1.Function) //nolint:ifshort
functionlog.Info("validate delete", "name", r.Name)

// TODO(user): fill in your validation logic upon object deletion.
return nil
return nil, nil
}
26 changes: 13 additions & 13 deletions pkg/webhook/sink_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ func (webhook *SinkWebhook) Default(ctx context.Context, obj runtime.Object) err
var _ admission.CustomValidator = &SinkWebhook{}

// ValidateCreate implements admission.CustomValidator so a webhook will be registered for the type
func (webhook *SinkWebhook) ValidateCreate(ctx context.Context, obj runtime.Object) error {
func (webhook *SinkWebhook) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
req, err := admission.RequestFromContext(ctx)
if err != nil {
return fmt.Errorf("expected admission.Request in ctx: %w", err)
return nil, fmt.Errorf("expected admission.Request in ctx: %w", err)
}
if req.Kind.Kind != sinkKind {
return fmt.Errorf("expected Kind %q got %q", sinkKind, req.Kind.Kind)
return nil, fmt.Errorf("expected Kind %q got %q", sinkKind, req.Kind.Kind)
}

r := obj.(*v1alpha1.Sink) //nolint:ifshort
Expand Down Expand Up @@ -235,42 +235,42 @@ func (webhook *SinkWebhook) ValidateCreate(ctx context.Context, obj runtime.Obje
}

if len(allErrs) == 0 {
return nil
return nil, nil
}

return apierrors.NewInvalid(schema.GroupKind{Group: "compute.functionmesh.io", Kind: "SinkWebhook"}, r.Name, allErrs)
return nil, apierrors.NewInvalid(schema.GroupKind{Group: "compute.functionmesh.io", Kind: "SinkWebhook"}, r.Name, allErrs)
}

// ValidateUpdate implements admission.CustomValidator so a webhook will be registered for the type
func (webhook *SinkWebhook) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) error {
func (webhook *SinkWebhook) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
req, err := admission.RequestFromContext(ctx)
if err != nil {
return fmt.Errorf("expected admission.Request in ctx: %w", err)
return nil, fmt.Errorf("expected admission.Request in ctx: %w", err)
}
if req.Kind.Kind != sinkKind {
return fmt.Errorf("expected Kind %q got %q", sinkKind, req.Kind.Kind)
return nil, fmt.Errorf("expected Kind %q got %q", sinkKind, req.Kind.Kind)
}

r := oldObj.(*v1alpha1.Sink) //nolint:ifshort
sinklog.Info("validate update", "name", r.Name)

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

// ValidateDelete implements admission.CustomValidator so a webhook will be registered for the type
func (webhook *SinkWebhook) ValidateDelete(ctx context.Context, obj runtime.Object) error {
func (webhook *SinkWebhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
req, err := admission.RequestFromContext(ctx)
if err != nil {
return fmt.Errorf("expected admission.Request in ctx: %w", err)
return nil, fmt.Errorf("expected admission.Request in ctx: %w", err)
}
if req.Kind.Kind != sinkKind {
return fmt.Errorf("expected Kind %q got %q", sinkKind, req.Kind.Kind)
return nil, fmt.Errorf("expected Kind %q got %q", sinkKind, req.Kind.Kind)
}

r := obj.(*v1alpha1.Sink) //nolint:ifshort
sinklog.Info("validate delete", "name", r.Name)

// TODO(user): fill in your validation logic upon object deletion.
return nil
return nil, nil
}
26 changes: 13 additions & 13 deletions pkg/webhook/source_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ func (webhook *SourceWebhook) Default(ctx context.Context, obj runtime.Object) e
var _ admission.CustomValidator = &SourceWebhook{}

// ValidateCreate implements admission.CustomValidator so a webhook will be registered for the type
func (webhook *SourceWebhook) ValidateCreate(ctx context.Context, obj runtime.Object) error {
func (webhook *SourceWebhook) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
req, err := admission.RequestFromContext(ctx)
if err != nil {
return fmt.Errorf("expected admission.Request in ctx: %w", err)
return nil, fmt.Errorf("expected admission.Request in ctx: %w", err)
}
if req.Kind.Kind != sourceKind {
return fmt.Errorf("expected Kind %q got %q", sourceKind, req.Kind.Kind)
return nil, fmt.Errorf("expected Kind %q got %q", sourceKind, req.Kind.Kind)
}

r := obj.(*v1alpha1.Source) //nolint:ifshort
Expand Down Expand Up @@ -225,42 +225,42 @@ func (webhook *SourceWebhook) ValidateCreate(ctx context.Context, obj runtime.Ob
}

if len(allErrs) == 0 {
return nil
return nil, nil
}

return apierrors.NewInvalid(schema.GroupKind{Group: "compute.functionmesh.io", Kind: "SourceWebhook"}, r.Name, allErrs)
return nil, apierrors.NewInvalid(schema.GroupKind{Group: "compute.functionmesh.io", Kind: "SourceWebhook"}, r.Name, allErrs)
}

// ValidateUpdate implements admission.CustomValidator so a webhook will be registered for the type
func (webhook *SourceWebhook) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) error {
func (webhook *SourceWebhook) ValidateUpdate(ctx context.Context, oldObj, newObj runtime.Object) (admission.Warnings, error) {
req, err := admission.RequestFromContext(ctx)
if err != nil {
return fmt.Errorf("expected admission.Request in ctx: %w", err)
return nil, fmt.Errorf("expected admission.Request in ctx: %w", err)
}
if req.Kind.Kind != sourceKind {
return fmt.Errorf("expected Kind %q got %q", sourceKind, req.Kind.Kind)
return nil, fmt.Errorf("expected Kind %q got %q", sourceKind, req.Kind.Kind)
}

r := oldObj.(*v1alpha1.Source) //nolint:ifshort
sourcelog.Info("validate update", "name", r.Name)

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

// ValidateDelete implements admission.CustomValidator so a webhook will be registered for the type
func (webhook *SourceWebhook) ValidateDelete(ctx context.Context, obj runtime.Object) error {
func (webhook *SourceWebhook) ValidateDelete(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
req, err := admission.RequestFromContext(ctx)
if err != nil {
return fmt.Errorf("expected admission.Request in ctx: %w", err)
return nil, fmt.Errorf("expected admission.Request in ctx: %w", err)
}
if req.Kind.Kind != sourceKind {
return fmt.Errorf("expected Kind %q got %q", sourceKind, req.Kind.Kind)
return nil, fmt.Errorf("expected Kind %q got %q", sourceKind, req.Kind.Kind)
}

r := obj.(*v1alpha1.Source) //nolint:ifshort
sourcelog.Info("validate delete", "name", r.Name)

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

0 comments on commit 343379e

Please sign in to comment.