Skip to content

Commit

Permalink
Conversion update (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmendesky committed Aug 31, 2022
1 parent cfa724c commit 6a3543b
Show file tree
Hide file tree
Showing 13 changed files with 1,098 additions and 111 deletions.
20 changes: 20 additions & 0 deletions apis/config/v1alpha2/groupversion_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Package v2 contains API Schema definitions for the config v2 API group
//+kubebuilder:object:generate=true
//+groupName=config.kubeflow.org
package v1alpha2

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "config.kubeflow.org", Version: "v1alpha2"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
39 changes: 39 additions & 0 deletions apis/config/v1alpha2/kfp_controller_config_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package v1alpha2

import (
"github.com/sky-uk/kfp-operator/apis"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
cfg "sigs.k8s.io/controller-runtime/pkg/config/v1alpha1"
)

type Configuration struct {
PipelineStorage string `json:"pipelineStorage,omitempty"`
KfpEndpoint string `json:"kfpEndpoint,omitempty"`

WorkflowTemplatePrefix string `json:"workflowTemplatePrefix,omitempty"`

Multiversion bool `json:"multiversion,omitempty"`

DefaultBeamArgs []apis.NamedValue `json:"defaultBeamArgs,omitempty"`

DefaultExperiment string `json:"defaultExperiment,omitempty"`

Debug apis.DebugOptions `json:"debug,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

type KfpControllerConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Workflows Configuration `json:"spec,omitempty"`

cfg.ControllerManagerConfigurationSpec `json:"controller,omitempty"`
}

//+kubebuilder:object:root=true

func init() {
SchemeBuilder.Register(&KfpControllerConfig{})
}
59 changes: 59 additions & 0 deletions apis/config/v1alpha2/zz_generated.deepcopy.go

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

1 change: 1 addition & 0 deletions apis/config/v1alpha3/kfp_controller_config_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Configuration struct {

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:storageversion

type KfpControllerConfig struct {
metav1.TypeMeta `json:",inline"`
Expand Down
27 changes: 7 additions & 20 deletions apis/pipelines/v1alpha2/experiment_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,16 @@ import (
)

var _ = Context("Experiment Conversion", func() {
var _ = Describe("ConvertTo", func() {

Specify("Copies all fields", func() {
var _ = Describe("Roundtrip", func() {
Specify("converts to and from the same object", func() {
src := RandomExperiment()
dst := v1alpha3.Experiment{}

Expect(src.ConvertTo(&dst)).To(Succeed())
Expect(dst.ObjectMeta).To(Equal(src.ObjectMeta))
Expect(dst.Spec.Description).To(Equal(src.Spec.Description))
Expect(dst.Status).To(Equal(src.Status))
})
})

var _ = Describe("ConvertFrom", func() {

Specify("Copies all fields", func() {
src := v1alpha3.RandomExperiment()
intermediate := v1alpha3.Experiment{}
dst := Experiment{}

Expect(dst.ConvertFrom(src)).To(Succeed())
Expect(dst.ObjectMeta).To(Equal(src.ObjectMeta))
Expect(dst.Spec.Description).To(Equal(src.Spec.Description))
Expect(dst.Status).To(Equal(src.Status))
Expect(src.ConvertTo(&intermediate)).To(Succeed())
Expect(dst.ConvertFrom(&intermediate)).To(Succeed())

Expect(&dst).To(Equal(src))
})
})

Expand Down
28 changes: 10 additions & 18 deletions apis/pipelines/v1alpha2/pipeline_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ var _ = Context("Pipeline Conversion", func() {
{Name: "c", Value: "d"},
}))
})

Specify("Copies all other fields", func() {
src := RandomPipeline()
dst := v1alpha3.Pipeline{}

Expect(src.ConvertTo(&dst)).To(Succeed())
Expect(dst.Spec.Image).To(Equal(src.Spec.Image))
Expect(dst.Spec.TfxComponents).To(Equal(src.Spec.TfxComponents))
Expect(dst.ObjectMeta).To(Equal(src.ObjectMeta))
Expect(dst.Status).To(Equal(src.Status))
})
})

var _ = Describe("ConvertFrom", func() {
Expand Down Expand Up @@ -89,15 +78,18 @@ var _ = Context("Pipeline Conversion", func() {
Expect(dst.ConvertFrom(&src)).NotTo(Succeed())
})

Specify("Copies all other fields", func() {
src := v1alpha3.RandomPipeline()
})

var _ = Describe("Roundtrip", func() {
Specify("converts to and from the same object", func() {
src := RandomPipeline()
intermediate := v1alpha3.Pipeline{}
dst := Pipeline{}

Expect(dst.ConvertFrom(src)).To(Succeed())
Expect(dst.Spec.Image).To(Equal(src.Spec.Image))
Expect(dst.Spec.TfxComponents).To(Equal(src.Spec.TfxComponents))
Expect(dst.ObjectMeta).To(Equal(src.ObjectMeta))
Expect(dst.Status).To(Equal(src.Status))
Expect(src.ConvertTo(&intermediate)).To(Succeed())
Expect(dst.ConvertFrom(&intermediate)).To(Succeed())

Expect(&dst).To(Equal(src))
})
})

Expand Down
6 changes: 6 additions & 0 deletions apis/pipelines/v1alpha2/runconfiguration_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ func (src *RunConfiguration) ConvertTo(dstRaw conversion.Hub) error {

dst.ObjectMeta = src.ObjectMeta
dst.Spec.RuntimeParameters = mapToNamedValues(src.Spec.RuntimeParameters)
dst.Spec.Pipeline = v1alpha3.PipelineIdentifier{Name: src.Spec.Pipeline.Name, Version: src.Spec.Pipeline.Version}
dst.Spec.Schedule = src.Spec.Schedule
dst.Spec.ExperimentName = src.Spec.ExperimentName
dst.Status = v1alpha3.RunConfigurationStatus(src.Status)

return nil
Expand All @@ -25,6 +28,9 @@ func (dst *RunConfiguration) ConvertFrom(srcRaw conversion.Hub) error {
if err != nil {
return err
}
dst.Spec.Pipeline = PipelineIdentifier{Name: src.Spec.Pipeline.Name, Version: src.Spec.Pipeline.Version}
dst.Spec.Schedule = src.Spec.Schedule
dst.Spec.ExperimentName = src.Spec.ExperimentName
dst.Status = RunConfigurationStatus(src.Status)

return nil
Expand Down
25 changes: 9 additions & 16 deletions apis/pipelines/v1alpha2/runconfiguration_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ var _ = Context("RunConfiguration Conversion", func() {
{Name: "c", Value: "d"},
}))
})

Specify("Copies all other fields", func() {
src := RandomRunConfiguration()
dst := v1alpha3.RunConfiguration{}

Expect(src.ConvertTo(&dst)).To(Succeed())
Expect(dst.ObjectMeta).To(Equal(src.ObjectMeta))
Expect(dst.Status.Status).To(Equal(src.Status.Status))
Expect(dst.Status.ObservedPipelineVersion).To(Equal(src.Status.ObservedPipelineVersion))
})
})

var _ = Describe("ConvertFrom", func() {
Expand All @@ -59,15 +49,18 @@ var _ = Context("RunConfiguration Conversion", func() {

Expect(dst.ConvertFrom(&src)).NotTo(Succeed())
})
})

Specify("Copies all other fields", func() {
src := v1alpha3.RandomRunConfiguration()
var _ = Describe("Roundtrip", func() {
Specify("converts to and from the same object", func() {
src := RandomRunConfiguration()
intermediate := v1alpha3.RunConfiguration{}
dst := RunConfiguration{}

Expect(dst.ConvertFrom(src)).To(Succeed())
Expect(dst.ObjectMeta).To(Equal(src.ObjectMeta))
Expect(dst.Status.Status).To(Equal(src.Status.Status))
Expect(dst.Status.ObservedPipelineVersion).To(Equal(src.Status.ObservedPipelineVersion))
Expect(src.ConvertTo(&intermediate)).To(Succeed())
Expect(dst.ConvertFrom(&intermediate)).To(Succeed())

Expect(&dst).To(Equal(src))
})
})

Expand Down

0 comments on commit 6a3543b

Please sign in to comment.