Skip to content

Commit

Permalink
wip tests for provider controller
Browse files Browse the repository at this point in the history
  • Loading branch information
aidandunlop committed Dec 17, 2024
1 parent 79dc7b4 commit 4cf3376
Show file tree
Hide file tree
Showing 9 changed files with 7,588 additions and 46 deletions.
24 changes: 24 additions & 0 deletions apis/config/v1alpha6/zz_generated.deepcopy.go

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

7,543 changes: 7,541 additions & 2 deletions config/crd/bases/config.kubeflow.org_kfpcontrollerconfigs.yaml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions config/crd/bases/pipelines.kubeflow.org_experiments.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ spec:
name:
type: string
type: object
serving:
type: string
synchronizationState:
type: string
version:
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/pipelines.kubeflow.org_pipelines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ spec:
name:
type: string
type: object
serving:
type: string
synchronizationState:
type: string
version:
Expand Down
5 changes: 5 additions & 0 deletions config/crd/bases/pipelines.kubeflow.org_providers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ spec:
type: object
spec:
properties:
cliImage:
type: string
defaultBeamArgs:
items:
properties:
Expand Down Expand Up @@ -205,6 +207,7 @@ spec:
type:
type: string
required:
- cliImage
- executionMode
- image
- pipelineRootStorage
Expand Down Expand Up @@ -291,6 +294,8 @@ spec:
name:
type: string
type: object
serving:
type: string
synchronizationState:
type: string
version:
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/pipelines.kubeflow.org_runs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ spec:
name:
type: string
type: object
serving:
type: string
synchronizationState:
type: string
version:
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/pipelines.kubeflow.org_runschedules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ spec:
name:
type: string
type: object
serving:
type: string
synchronizationState:
type: string
version:
Expand Down
52 changes: 9 additions & 43 deletions controllers/pipelines/provider_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ type ProviderReconciler struct {
Scheme *runtime.Scheme
}

func NewProviderReconciler(ec K8sExecutionContext, scheme *runtime.Scheme, config config.KfpControllerConfigSpec) *ProviderReconciler {
func NewProviderReconciler(ec K8sExecutionContext, config config.KfpControllerConfigSpec) *ProviderReconciler {
return &ProviderReconciler{
StateHandler: StateHandler[*pipelinesv1.Provider]{},
ResourceReconciler: ResourceReconciler[*pipelinesv1.Provider]{
EC: ec,
Config: config,
},
Scheme: scheme,
Scheme: ec.Scheme,
}
}

Expand All @@ -51,28 +51,18 @@ func (r *ProviderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
return ctrl.Result{}, client.IgnoreNotFound(err)
}

logger.V(2).Info("found provider", "resource", provider)
logger.Info("found provider", "resource", provider)

existingProviderDeployment, err := r.fetchProviderServiceDeployment(ctx, provider, req.Namespace)
desiredProviderDeployment, err := r.constructProviderServiceDeployment(provider, req.Namespace, r.Config)
if err != nil {
logger.Error(err, "unable to fetch provider service deployment")
logger.Error(err, "unable to construct provider service deployment")
return ctrl.Result{}, err
}
logger.Info("created provider deployment", "deployment", desiredProviderDeployment)

if existingProviderDeployment == nil {
providerDeployment, err := r.constructProviderServiceDeployment(provider, req.Namespace, r.Config)
if err != nil {
logger.Error(err, "unable to construct provider service deployment")
return ctrl.Result{}, err
}
if err := r.EC.Client.Create(ctx, providerDeployment); err != nil {
logger.Error(err, "unable to create provider service deployment")
return ctrl.Result{}, err
}
logger.Info("created provider service deployment", "resource", providerDeployment)
} else {
logger.V(2).Info("found provider service deployment", "resource", existingProviderDeployment)
// ensure that deployment matches the desired state
if err := r.EC.Client.Patch(ctx, desiredProviderDeployment, client.Apply, client.FieldOwner("provider-controller-provider")); err != nil {
logger.Error(err, "unable to update provider service deployment")
return ctrl.Result{}, err
}

duration := time.Since(startTime)
Expand All @@ -89,26 +79,6 @@ func (r *ProviderReconciler) SetupWithManager(mgr ctrl.Manager) error {
Complete(r)
}

func (r *ProviderReconciler) fetchProviderServiceDeployment(ctx context.Context, provider *pipelinesv1.Provider, namespace string) (*appsv1.Deployment, error) {
deployments := &appsv1.DeploymentList{}
if err := r.EC.Client.NonCached.List(ctx, deployments, client.InNamespace(provider.Namespace)); err != nil {
return nil, err
}
var providerDeployment *appsv1.Deployment
for _, deployment := range deployments.Items {
if metav1.IsControlledBy(&deployment, provider) {
providerDeployment = &deployment
break // TODO: handle multiple deployments
}
}

if providerDeployment == nil {
// Do we need to return an error here?
return nil, fmt.Errorf("provider service deployment not found")
}
return providerDeployment, nil
}

func (r *ProviderReconciler) constructProviderServiceDeployment(provider *pipelinesv1.Provider, namespace string, config config.KfpControllerConfigSpec) (*appsv1.Deployment, error) {
replicas := int32(config.DefaultProviderValues.Replicas)

Expand All @@ -125,12 +95,8 @@ func (r *ProviderReconciler) constructProviderServiceDeployment(provider *pipeli
}
}

const providerLabelKey = "provider"
podTemplate.ObjectMeta.Labels[providerLabelKey] = provider.Name
podTemplate.Spec.ServiceAccountName = provider.Spec.ServiceAccount

labels := config.DefaultProviderValues.Labels
labels[providerLabelKey] = provider.Name

deployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func main() {
os.Exit(1)
}

if err = pipelinescontrollers.NewProviderReconciler(ec, scheme, ctrlConfig.Spec).SetupWithManager(mgr); err != nil {
if err = pipelinescontrollers.NewProviderReconciler(ec, ctrlConfig.Spec).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Provider")
os.Exit(1)
}
Expand Down

0 comments on commit 4cf3376

Please sign in to comment.