Skip to content

Commit

Permalink
Add overrides within provider deployment construction
Browse files Browse the repository at this point in the history
  • Loading branch information
TobyPinfold committed Dec 12, 2024
1 parent c555c38 commit 0667f07
Showing 1 changed file with 25 additions and 28 deletions.
53 changes: 25 additions & 28 deletions controllers/pipelines/provider_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"
)

// ProviderReconciler reconciles a Provider object
type ProviderReconciler struct {
StateHandler[*pipelinesv1.Provider]
ResourceReconciler[*pipelinesv1.Provider]
Expand Down Expand Up @@ -60,7 +59,7 @@ func (r *ProviderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
}

if providerServiceDeployment == nil {
providerServiceDeployment = constructProviderServiceDeployment(providerServiceName, req.Namespace, provider)
providerServiceDeployment = constructProviderDeployment(providerServiceName, req.Namespace, provider, r.Config)
if err := r.EC.Client.Create(ctx, providerServiceDeployment); err != nil {
logger.Error(err, "unable to create provider service deployment")
return ctrl.Result{}, err
Expand Down Expand Up @@ -103,41 +102,39 @@ func (r *ProviderReconciler) fetchProviderServiceDeployment(ctx context.Context,
return deployment, nil
}

func constructProviderServiceDeployment(name, namespace string, provider *pipelinesv1.Provider) *appsv1.Deployment {
var replicas int32 = 1
func replaceImageForContainersMarkedAsProviderService(containers []v1.Container, image string) []v1.Container {
for _, a := range containers {
if a.Name == "provider-service" {
a.Image = image
}
}
return containers
}

func constructProviderDeployment(name, namespace string, provider *pipelinesv1.Provider, config config.KfpControllerConfigSpec) *appsv1.Deployment {

replicas := int32(config.DefaultProviderValues.Replicas)

podTemplate := config.DefaultProviderValues.PodTemplateSpec
podTemplate.Spec.Containers = replaceImageForContainersMarkedAsProviderService(podTemplate.Spec.Containers, provider.Spec.Image)

const providerLabelKey = "provider"
podTemplate.ObjectMeta.Labels[providerLabelKey] = provider.GetName()
labels := config.DefaultProviderValues.Labels
labels[providerLabelKey] = provider.GetName()

return &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Labels: map[string]string{
"app": "provider-service",
"provider": provider.GetName(),
},
Labels: labels,
},
Spec: appsv1.DeploymentSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "provider-service",
"provider": provider.GetName(),
},
MatchLabels: labels,
},
Replicas: &replicas,
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": "provider-service",
"provider": provider.GetName(),
},
},
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Name: "provider-service",
Image: provider.Spec.Image,
},
},
},
},
Template: podTemplate,
},
}
}

0 comments on commit 0667f07

Please sign in to comment.