Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ webhooks:
service:
name: {{ include "dynamo-operator.fullname" . }}-webhook-service
namespace: {{ .Release.Namespace }}
path: /validate-nvidia-com-v1alpha1-dynamocomponentdeployment
path: /validate/nvidia.com/v1beta1/dynamocomponentdeployments
failurePolicy: {{ .Values.webhook.failurePolicy }}
name: vdynamocomponentdeployment.kb.io
{{- if .Values.webhook.namespaceSelector }}
Expand All @@ -59,7 +59,7 @@ webhooks:
- apiGroups:
- nvidia.com
apiVersions:
- v1alpha1
- v1beta1
operations:
- CREATE
- UPDATE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"fmt"
"strings"

nvidiacomv1alpha1 "github.com/ai-dynamo/dynamo/deploy/operator/api/v1alpha1"
nvidiacomv1beta1 "github.com/ai-dynamo/dynamo/deploy/operator/api/v1beta1"
"github.com/ai-dynamo/dynamo/deploy/operator/internal/consts"
"github.com/ai-dynamo/dynamo/deploy/operator/internal/features"
Expand All @@ -36,9 +35,8 @@ import (
)

const (
dgdDefaultingWebhookName = "dynamographdeployment-defaulting-webhook"
dgdV1Alpha1DefaultingWebhookPath = "/mutate-nvidia-com-v1alpha1-dynamographdeployment"
dgdV1Beta1DefaultingWebhookPath = "/mutate/nvidia.com/v1beta1/dynamographdeployments"
dgdDefaultingWebhookName = "dynamographdeployment-defaulting-webhook"
dgdDefaultingWebhookPath = "/mutate/nvidia.com/v1beta1/dynamographdeployments"
)

// DGDDefaulter is a mutating webhook handler that stamps DynamoGraphDeployments
Expand All @@ -48,13 +46,6 @@ type DGDDefaulter struct {
OperatorVersion string
}

// dgdV1Alpha1Defaulter keeps the previous endpoint available during the
// v1alpha1-to-v1beta1 admission migration. It applies v1beta1 defaulting and
// converts the result back to the object version used by the legacy endpoint.
type dgdV1Alpha1Defaulter struct {
defaulter *DGDDefaulter
}

// NewDGDDefaulter creates a new DGDDefaulter with the given operator version.
func NewDGDDefaulter(operatorVersion string) *DGDDefaulter {
return &DGDDefaulter{
Expand All @@ -70,6 +61,8 @@ func NewDGDDefaulter(operatorVersion string) *DGDDefaulter {
// On CREATE: stamps nvidia.com/dynamo-operator-origin-version with the operator version.
// On UPDATE/DELETE: the origin version annotation is immutable once set.
func (d *DGDDefaulter) Default(ctx context.Context, obj runtime.Object) error {
logger := log.FromContext(ctx).WithName(dgdDefaultingWebhookName)

if err := internalwebhook.ValidateAdmissionGVK(ctx, nvidiacomv1beta1.DynamoGraphDeploymentGVK); err != nil {
return err
}
Expand All @@ -78,14 +71,6 @@ func (d *DGDDefaulter) Default(ctx context.Context, obj runtime.Object) error {
if !ok {
return fmt.Errorf("expected DynamoGraphDeployment but got %T", obj)
}
return d.defaultV1Beta1(ctx, dgd)
}

func (d *DGDDefaulter) defaultV1Beta1(
ctx context.Context,
dgd *nvidiacomv1beta1.DynamoGraphDeployment,
) error {
logger := log.FromContext(ctx).WithName(dgdDefaultingWebhookName)

req, err := admission.RequestFromContext(ctx)
if err != nil {
Expand Down Expand Up @@ -133,46 +118,10 @@ func (d *DGDDefaulter) isGrovePathway(ctx context.Context, dgd *nvidiacomv1beta1

// RegisterWithManager registers the defaulting webhook with the manager.
func (d *DGDDefaulter) RegisterWithManager(mgr manager.Manager, gate features.Gate) error {
betaDefaulter := internalwebhook.NewLeaseAwareDefaulter(d, internalwebhook.GetExcludedNamespaces())
betaWebhook := internalwebhook.WithGate(admission.
WithCustomDefaulter(mgr.GetScheme(), &nvidiacomv1beta1.DynamoGraphDeployment{}, betaDefaulter).
defaulter := internalwebhook.NewLeaseAwareDefaulter(d, internalwebhook.GetExcludedNamespaces())
webhook := internalwebhook.WithGate(admission.
WithCustomDefaulter(mgr.GetScheme(), &nvidiacomv1beta1.DynamoGraphDeployment{}, defaulter).
WithRecoverPanic(true), gate)
mgr.GetWebhookServer().Register(dgdV1Beta1DefaultingWebhookPath, betaWebhook)

// TODO(1.5): Remove the v1alpha1 endpoint and defaulter after 1.3 is no longer
// a supported upgrade or rollback target.
alphaDefaulter := &dgdV1Alpha1Defaulter{defaulter: d}
alphaDefaulterWithLease := internalwebhook.NewLeaseAwareDefaulter(alphaDefaulter, internalwebhook.GetExcludedNamespaces())
alphaWebhook := internalwebhook.WithGate(admission.
WithCustomDefaulter(mgr.GetScheme(), &nvidiacomv1alpha1.DynamoGraphDeployment{}, alphaDefaulterWithLease).
WithRecoverPanic(true), gate)
mgr.GetWebhookServer().Register(dgdV1Alpha1DefaultingWebhookPath, alphaWebhook)
return nil
}

func (d *dgdV1Alpha1Defaulter) Default(ctx context.Context, obj runtime.Object) error {
if err := internalwebhook.ValidateAdmissionGVK(ctx, nvidiacomv1alpha1.DynamoGraphDeploymentGVK); err != nil {
return err
}

alpha, ok := obj.(*nvidiacomv1alpha1.DynamoGraphDeployment)
if !ok {
return fmt.Errorf("expected DynamoGraphDeployment but got %T", obj)
}

beta, err := internalwebhook.ConvertDynamoGraphDeploymentToV1Beta1(alpha)
if err != nil {
return err
}
if err := d.defaulter.defaultV1Beta1(ctx, beta); err != nil {
return err
}

converted, err := internalwebhook.ConvertDynamoGraphDeploymentToV1Alpha1(beta)
if err != nil {
return err
}
converted.TypeMeta = alpha.TypeMeta
*alpha = *converted
mgr.GetWebhookServer().Register(dgdDefaultingWebhookPath, webhook)
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"context"
"testing"

nvidiacomv1alpha1 "github.com/ai-dynamo/dynamo/deploy/operator/api/v1alpha1"
nvidiacomv1beta1 "github.com/ai-dynamo/dynamo/deploy/operator/api/v1beta1"
"github.com/ai-dynamo/dynamo/deploy/operator/internal/consts"
"github.com/ai-dynamo/dynamo/deploy/operator/internal/features"
Expand Down Expand Up @@ -438,27 +437,3 @@ func TestDGDDefaulter_DefaultsGroveMinAvailable(t *testing.T) {
})
}
}

func TestDGDV1Alpha1Defaulter_Default(t *testing.T) {
dgd := &nvidiacomv1alpha1.DynamoGraphDeployment{
ObjectMeta: metav1.ObjectMeta{Name: "test", Namespace: "default"},
Spec: nvidiacomv1alpha1.DynamoGraphDeploymentSpec{
Services: map[string]*nvidiacomv1alpha1.DynamoComponentDeploymentSharedSpec{
"worker": {
ComponentType: consts.ComponentTypeWorker,
},
},
},
}
defaulter := &dgdV1Alpha1Defaulter{defaulter: NewDGDDefaulter("0.9.0")}

if err := defaulter.Default(admissionCtx(admissionv1.Create, nvidiacomv1alpha1.DynamoGraphDeploymentGVK), dgd); err != nil {
t.Fatalf("Default() unexpected error: %v", err)
}
if got := dgd.Annotations[consts.KubeAnnotationDynamoOperatorOriginVersion]; got != "0.9.0" {
t.Errorf("origin annotation = %q, want %q", got, "0.9.0")
}
if got := dgd.Spec.Services["worker"].Replicas; got == nil || *got != 1 {
t.Errorf("worker replicas = %v, want 1", got)
}
}

This file was deleted.

Loading
Loading