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

Run workflows in provider namespace #428

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
33 changes: 27 additions & 6 deletions apis/pipelines/v1alpha5/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ package v1alpha5
import (
"github.com/sky-uk/kfp-operator/apis"
hub "github.com/sky-uk/kfp-operator/apis/pipelines/v1alpha6"
"github.com/sky-uk/kfp-operator/argo/common"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var DefaultProvider string

var ResourceAnnotations = struct {
Provider string
Provider string
ProviderNamespace string
}{
Provider: apis.Group + "/provider",
Provider: apis.Group + "/provider",
ProviderNamespace: apis.Group + "/providerNamespace",
}

func convertArtifactsTo(outputArtifact []OutputArtifact) []hub.OutputArtifact {
Expand Down Expand Up @@ -65,16 +68,34 @@ func removeProviderAnnotation(resource v1.Object) {
delete(resource.GetAnnotations(), ResourceAnnotations.Provider)
}

func convertProviderAndIdTo(providerAndId ProviderAndId) hub.ProviderAndId {
func getProviderNamespaceAnnotation(resource v1.Object) string {
if providerNamespace, hasProviderNamespace := resource.GetAnnotations()[ResourceAnnotations.ProviderNamespace]; hasProviderNamespace {
return providerNamespace
}
return ""
}

func setProviderNamespaceAnnotation(namespace string, resource *v1.ObjectMeta) {
v1.SetMetaDataAnnotation(resource, ResourceAnnotations.ProviderNamespace, namespace)
}

func removeProviderNamespaceAnnotation(resource v1.Object) {
delete(resource.GetAnnotations(), ResourceAnnotations.ProviderNamespace)
}

func convertProviderAndIdTo(providerAndId ProviderAndId, namespace string) hub.ProviderAndId {
return hub.ProviderAndId{
Name: providerAndId.Provider,
Id: providerAndId.Id,
Name: common.NamespacedName{
Name: providerAndId.Provider,
Namespace: namespace,
},
Id: providerAndId.Id,
}
}

func convertProviderAndIdFrom(providerAndId hub.ProviderAndId) ProviderAndId {
return ProviderAndId{
Provider: providerAndId.Name,
Provider: providerAndId.Name.Name,
Id: providerAndId.Id,
}
}
9 changes: 6 additions & 3 deletions apis/pipelines/v1alpha5/experiment_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ func (src *Experiment) ConvertTo(dstRaw conversion.Hub) error {
return err
}

dst.Spec.Provider = getProviderAnnotation(src)
dst.TypeMeta.APIVersion = dstApiVersion
dst.Status.Provider = convertProviderAndIdTo(src.Status.ProviderId)
dst.Spec.Provider.Name = getProviderAnnotation(src)
dst.Spec.Provider.Namespace = getProviderNamespaceAnnotation(src)
dst.Status.Provider = convertProviderAndIdTo(src.Status.ProviderId, dst.Spec.Provider.Namespace)

removeProviderAnnotation(dst)
removeProviderNamespaceAnnotation(dst)

return nil
}
Expand All @@ -33,7 +35,8 @@ func (dst *Experiment) ConvertFrom(srcRaw conversion.Hub) error {
return err
}

setProviderAnnotation(src.Spec.Provider, &dst.ObjectMeta)
setProviderAnnotation(src.Spec.Provider.Name, &dst.ObjectMeta)
setProviderNamespaceAnnotation(src.Spec.Provider.Namespace, &dst.ObjectMeta)
dst.TypeMeta.APIVersion = dstApiVersion
dst.Status.ProviderId = convertProviderAndIdFrom(src.Status.Provider)

Expand Down
1 change: 1 addition & 0 deletions apis/pipelines/v1alpha5/experiment_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var _ = Context("Experiment Conversion", PropertyBased, func() {
Specify("converts to and from the same object", func() {
src := RandomExperiment()
setProviderAnnotation(apis.RandomLowercaseString(), &src.ObjectMeta)
setProviderNamespaceAnnotation(apis.RandomLowercaseString(), &src.ObjectMeta)
intermediate := &hub.Experiment{}
dst := &Experiment{}

Expand Down
9 changes: 6 additions & 3 deletions apis/pipelines/v1alpha5/pipeline_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ func (src *Pipeline) ConvertTo(dstRaw conversion.Hub) error {
return err
}

dst.Spec.Provider = getProviderAnnotation(src)
dst.TypeMeta.APIVersion = dstApiVersion
dst.Status.Provider = convertProviderAndIdTo(src.Status.ProviderId)
dst.Spec.Provider.Name = getProviderAnnotation(src)
dst.Spec.Provider.Namespace = getProviderNamespaceAnnotation(src)
dst.Status.Provider = convertProviderAndIdTo(src.Status.ProviderId, dst.Spec.Provider.Namespace)

removeProviderAnnotation(dst)
removeProviderNamespaceAnnotation(dst)

return nil
}
Expand All @@ -32,7 +34,8 @@ func (dst *Pipeline) ConvertFrom(srcRaw conversion.Hub) error {
if err != nil {
return err
}
setProviderAnnotation(src.Spec.Provider, &dst.ObjectMeta)
setProviderAnnotation(src.Spec.Provider.Name, &dst.ObjectMeta)
setProviderNamespaceAnnotation(src.Spec.Provider.Namespace, &dst.ObjectMeta)
dst.TypeMeta.APIVersion = dstApiVersion
dst.Status.ProviderId = convertProviderAndIdFrom(src.Status.Provider)

Expand Down
1 change: 1 addition & 0 deletions apis/pipelines/v1alpha5/pipeline_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var _ = Context("Pipeline Conversion", PropertyBased, func() {
Specify("converts to and from the same object", func() {
src := RandomPipeline()
setProviderAnnotation(apis.RandomLowercaseString(), &src.ObjectMeta)
setProviderNamespaceAnnotation(apis.RandomLowercaseString(), &src.ObjectMeta)
intermediate := &hub.Pipeline{}
dst := &Pipeline{}

Expand Down
11 changes: 8 additions & 3 deletions apis/pipelines/v1alpha5/run_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/conversion"
)

// v1alpha5 to v1alpha6
func (src *Run) ConvertTo(dstRaw conversion.Hub) error {
dst := dstRaw.(*hub.Run)
dstApiVersion := dst.APIVersion
Expand All @@ -16,14 +17,17 @@ func (src *Run) ConvertTo(dstRaw conversion.Hub) error {
}

dst.TypeMeta.APIVersion = dstApiVersion
dst.Spec.Provider = getProviderAnnotation(src)
dst.Status.Provider = convertProviderAndIdTo(src.Status.ProviderId)
dst.Spec.Provider.Name = getProviderAnnotation(src)
dst.Spec.Provider.Namespace = getProviderNamespaceAnnotation(src)
dst.Status.Provider = convertProviderAndIdTo(src.Status.ProviderId, dst.Spec.Provider.Namespace)

removeProviderAnnotation(dst)
removeProviderNamespaceAnnotation(dst)

return nil
}

// v1alpha6 to v1alpha5
func (dst *Run) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*hub.Run)
dstApiVersion := dst.APIVersion
Expand All @@ -32,7 +36,8 @@ func (dst *Run) ConvertFrom(srcRaw conversion.Hub) error {
if err != nil {
return err
}
setProviderAnnotation(src.Spec.Provider, &dst.ObjectMeta)
setProviderAnnotation(src.Spec.Provider.Name, &dst.ObjectMeta)
setProviderNamespaceAnnotation(src.Spec.Provider.Namespace, &dst.ObjectMeta)
dst.TypeMeta.APIVersion = dstApiVersion
dst.Status.ProviderId = convertProviderAndIdFrom(src.Status.Provider)

Expand Down
1 change: 1 addition & 0 deletions apis/pipelines/v1alpha5/run_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var _ = Context("Run Conversion", PropertyBased, func() {
Specify("converts to and from the same object", func() {
src := RandomRun()
setProviderAnnotation(apis.RandomLowercaseString(), &src.ObjectMeta)
setProviderNamespaceAnnotation(apis.RandomLowercaseString(), &src.ObjectMeta)
intermediate := &hub.Run{}
dst := &Run{}

Expand Down
7 changes: 5 additions & 2 deletions apis/pipelines/v1alpha5/runconfiguration_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ func (src *RunConfiguration) ConvertTo(dstRaw conversion.Hub) error {
}

dst.ObjectMeta = src.ObjectMeta
dst.Spec.Run.Provider = getProviderAnnotation(src)
dst.Spec.Run.Provider.Name = getProviderAnnotation(src)
dst.Spec.Run.Provider.Namespace = getProviderNamespaceAnnotation(src)
removeProviderAnnotation(dst)
removeProviderNamespaceAnnotation(dst)
dst.Spec.Run.Pipeline = hub.PipelineIdentifier{
Name: src.Spec.Run.Pipeline.Name,
Version: src.Spec.Run.Pipeline.Version,
Expand All @@ -40,7 +42,8 @@ func (dst *RunConfiguration) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*hub.RunConfiguration)
v1alpha6Remainder := hub.RunConfigurationConversionRemainder{}
dst.ObjectMeta = src.ObjectMeta
setProviderAnnotation(src.Spec.Run.Provider, &dst.ObjectMeta)
setProviderAnnotation(src.Spec.Run.Provider.Name, &dst.ObjectMeta)
setProviderNamespaceAnnotation(src.Spec.Run.Provider.Namespace, &dst.ObjectMeta)
dst.Spec.Run.Pipeline = PipelineIdentifier{
Name: src.Spec.Run.Pipeline.Name,
Version: src.Spec.Run.Pipeline.Version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var _ = Context("RunConfiguration Conversion", PropertyBased, func() {
},
}
setProviderAnnotation(apis.RandomLowercaseString(), &src.ObjectMeta)
setProviderNamespaceAnnotation(apis.RandomLowercaseString(), &src.ObjectMeta)
intermediate := &hub.RunConfiguration{}
dst := &RunConfiguration{}

Expand Down
9 changes: 6 additions & 3 deletions apis/pipelines/v1alpha5/runschedule_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ func (src *RunSchedule) ConvertTo(dstRaw conversion.Hub) error {
return err
}
dst.ObjectMeta = src.ObjectMeta
dst.Spec.Provider = getProviderAnnotation(src)
dst.Spec.Provider.Name = getProviderAnnotation(src)
dst.Spec.Provider.Namespace = getProviderNamespaceAnnotation(src)
removeProviderAnnotation(dst)
removeProviderNamespaceAnnotation(dst)
dst.Spec.Pipeline = hub.PipelineIdentifier{
Name: src.Spec.Pipeline.Name,
Version: src.Spec.Pipeline.Version,
Expand All @@ -31,7 +33,7 @@ func (src *RunSchedule) ConvertTo(dstRaw conversion.Hub) error {
if err := pipelines.TransformInto(src.Status, &dst.Status); err != nil {
return err
}
dst.Status.Provider = convertProviderAndIdTo(src.Status.ProviderId)
dst.Status.Provider = convertProviderAndIdTo(src.Status.ProviderId, dst.Spec.Provider.Namespace)

return nil
}
Expand All @@ -40,7 +42,8 @@ func (dst *RunSchedule) ConvertFrom(srcRaw conversion.Hub) error {
src := srcRaw.(*hub.RunSchedule)
v1alpha6Remainder := hub.RunScheduleConversionRemainder{}
dst.ObjectMeta = src.ObjectMeta
setProviderAnnotation(src.Spec.Provider, &dst.ObjectMeta)
setProviderAnnotation(src.Spec.Provider.Name, &dst.ObjectMeta)
setProviderNamespaceAnnotation(src.Spec.Provider.Namespace, &dst.ObjectMeta)
dst.Spec.Pipeline = PipelineIdentifier{
Name: src.Spec.Pipeline.Name,
Version: src.Spec.Pipeline.Version,
Expand Down
1 change: 1 addition & 0 deletions apis/pipelines/v1alpha5/runschedule_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var _ = Context("RunSchedule Conversion", PropertyBased, func() {
Specify("converts to and from the same object", func() {
src := RandomRunSchedule()
setProviderAnnotation(apis.RandomLowercaseString(), &src.ObjectMeta)
setProviderNamespaceAnnotation(apis.RandomLowercaseString(), &src.ObjectMeta)
intermediate := &hub.RunSchedule{}
dst := &RunSchedule{}

Expand Down
5 changes: 3 additions & 2 deletions apis/pipelines/v1alpha6/experiment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"fmt"

"github.com/sky-uk/kfp-operator/apis/pipelines"
"github.com/sky-uk/kfp-operator/argo/common"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)

type ExperimentSpec struct {
Provider string `json:"provider" yaml:"provider"`
Description string `json:"description,omitempty"`
Provider common.NamespacedName `json:"provider" yaml:"provider"`
Description string `json:"description,omitempty"`
}

func (es Experiment) ComputeHash() []byte {
Expand Down
11 changes: 6 additions & 5 deletions apis/pipelines/v1alpha6/pipeline_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ import (
. "github.com/docker/distribution/reference"
"github.com/sky-uk/kfp-operator/apis"
"github.com/sky-uk/kfp-operator/apis/pipelines"
"github.com/sky-uk/kfp-operator/argo/common"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)

type PipelineSpec struct {
Provider string `json:"provider" yaml:"provider"`
Image string `json:"image" yaml:"image"`
TfxComponents string `json:"tfxComponents" yaml:"tfxComponents"`
Env []apis.NamedValue `json:"env,omitempty" yaml:"env"`
BeamArgs []apis.NamedValue `json:"beamArgs,omitempty"`
Provider common.NamespacedName `json:"provider" yaml:"provider"`
Image string `json:"image" yaml:"image"`
TfxComponents string `json:"tfxComponents" yaml:"tfxComponents"`
Env []apis.NamedValue `json:"env,omitempty" yaml:"env"`
BeamArgs []apis.NamedValue `json:"beamArgs,omitempty"`
}

func (ps Pipeline) ComputeHash() []byte {
Expand Down
8 changes: 8 additions & 0 deletions apis/pipelines/v1alpha6/provider_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1alpha6

import (
"github.com/sky-uk/kfp-operator/apis"
"github.com/sky-uk/kfp-operator/argo/common"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -42,6 +43,13 @@ func (p Provider) GetNamespacedName() types.NamespacedName {
}
}

func (p Provider) GetCommonNamespacedName() common.NamespacedName {
return common.NamespacedName{
Name: p.Name,
Namespace: p.Namespace,
}
}

func (e Provider) GetKind() string {
return "provider"
}
Expand Down
10 changes: 5 additions & 5 deletions apis/pipelines/v1alpha6/run_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ type ValueFrom struct {
}

type RunSpec struct {
Provider string `json:"provider" yaml:"provider"`
Pipeline PipelineIdentifier `json:"pipeline,omitempty"`
ExperimentName string `json:"experimentName,omitempty"`
RuntimeParameters []RuntimeParameter `json:"runtimeParameters,omitempty"`
Artifacts []OutputArtifact `json:"artifacts,omitempty"`
Provider common.NamespacedName `json:"provider" yaml:"provider"`
Pipeline PipelineIdentifier `json:"pipeline,omitempty"`
ExperimentName string `json:"experimentName,omitempty"`
RuntimeParameters []RuntimeParameter `json:"runtimeParameters,omitempty"`
Artifacts []OutputArtifact `json:"artifacts,omitempty"`
}

func (runSpec *RunSpec) ResolveRuntimeParameters(dependencies Dependencies) ([]apis.NamedValue, error) {
Expand Down
3 changes: 2 additions & 1 deletion apis/pipelines/v1alpha6/runconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/sky-uk/kfp-operator/apis"
"github.com/sky-uk/kfp-operator/apis/pipelines"
"github.com/sky-uk/kfp-operator/argo/common"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)
Expand Down Expand Up @@ -62,7 +63,7 @@ type LatestRuns struct {

type RunConfigurationStatus struct {
SynchronizationState apis.SynchronizationState `json:"synchronizationState,omitempty"`
Provider string `json:"provider,omitempty"`
Provider common.NamespacedName `json:"provider,omitempty"`
ObservedPipelineVersion string `json:"observedPipelineVersion,omitempty"`
TriggeredPipelineVersion string `json:"triggeredPipelineVersion,omitempty"`
LatestRuns LatestRuns `json:"latestRuns,omitempty"`
Expand Down
13 changes: 7 additions & 6 deletions apis/pipelines/v1alpha6/runschedule_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import (

"github.com/sky-uk/kfp-operator/apis"
"github.com/sky-uk/kfp-operator/apis/pipelines"
"github.com/sky-uk/kfp-operator/argo/common"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
)

type RunScheduleSpec struct {
Provider string `json:"provider" yaml:"provider"`
Pipeline PipelineIdentifier `json:"pipeline,omitempty"`
ExperimentName string `json:"experimentName,omitempty"`
RuntimeParameters []apis.NamedValue `json:"runtimeParameters,omitempty"`
Artifacts []OutputArtifact `json:"artifacts,omitempty"`
Schedule Schedule `json:"schedule,omitempty"`
Provider common.NamespacedName `json:"provider" yaml:"provider"`
Pipeline PipelineIdentifier `json:"pipeline,omitempty"`
ExperimentName string `json:"experimentName,omitempty"`
RuntimeParameters []apis.NamedValue `json:"runtimeParameters,omitempty"`
Artifacts []OutputArtifact `json:"artifacts,omitempty"`
Schedule Schedule `json:"schedule,omitempty"`
}

type Schedule struct {
Expand Down
5 changes: 3 additions & 2 deletions apis/pipelines/v1alpha6/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v1alpha6
import (
"github.com/sky-uk/kfp-operator/apis"
"github.com/sky-uk/kfp-operator/apis/pipelines"
"github.com/sky-uk/kfp-operator/argo/common"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -14,8 +15,8 @@ var ConditionTypes = struct {

// +kubebuilder:object:generate=true
type ProviderAndId struct {
Name string `json:"name,omitempty"`
Id string `json:"id,omitempty"`
Name common.NamespacedName `json:"name,omitempty"` //TODO: rename to NamespacedName
Id string `json:"id,omitempty"`
}

func ConditionStatusForSynchronizationState(state apis.SynchronizationState) metav1.ConditionStatus {
Expand Down
Loading