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

Add configuration to pipeline stanza of DSC to enable InstructLab pipeline #1484

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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ spec:
managementState: Managed
datasciencepipelines:
managementState: Managed
managedPipelines:
instructLab:
state: Managed
kserve:
managementState: Managed
nim:
Expand Down
23 changes: 23 additions & 0 deletions apis/components/v1alpha1/datasciencepipelines/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// +kubebuilder:object:generate=true

// Package datasciencepipelines provides a set of types used for DataSciencePipelines component
package datasciencepipelines

import operatorv1 "github.com/openshift/api/operator/v1"

type ManagedPipelinesSpec struct {
// Configures whether to automatically import the InstructLab pipeline.
// You must enable the trainingoperator component to run the InstructLab pipeline.
InstructLab ManagedPipelineOptions `json:"instructLab,omitempty"`
}

type ManagedPipelineOptions struct {
// Set to one of the following values:
//
// - "Managed" : This pipeline is automatically imported.
// - "Removed" : This pipeline is not automatically imported when a new pipeline server or DSPA is created. If previously set to "Managed", setting to "Removed" does not remove existing preloaded pipelines but does prevent future updates from being imported.
//
// +kubebuilder:validation:Enum=Managed;Removed
// +kubebuilder:default=Removed
State operatorv1.ManagementState `json:"state,omitempty"`
}

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

2 changes: 2 additions & 0 deletions apis/components/v1alpha1/datasciencepipelines_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
"github.com/opendatahub-io/opendatahub-operator/v2/apis/common"
"github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1/datasciencepipelines"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -51,6 +52,7 @@ type DataSciencePipelinesSpec struct {

type DataSciencePipelinesCommonSpec struct {
common.DevFlagsSpec `json:",inline"`
PreloadedPipelines datasciencepipelines.ManagedPipelinesSpec `json:"managedPipelines,omitempty"`
}

// DataSciencePipelinesCommonStatus defines the shared observed state of DataSciencePipelines
Expand Down
1 change: 1 addition & 0 deletions apis/components/v1alpha1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@ spec:
type: object
type: array
type: object
managedPipelines:
properties:
instructLab:
description: |-
Configures whether to automatically import the InstructLab pipeline.
You must enable the trainingoperator component to run the InstructLab pipeline.
properties:
state:
default: Removed
description: |-
Set to one of the following values:

- "Managed" : This pipeline is automatically imported.
- "Removed" : This pipeline is not automatically imported when a new pipeline server or DSPA is created. If previously set to "Managed", setting to "Removed" does not remove existing preloaded pipelines but does prevent future updates from being imported.
enum:
- Managed
- Removed
pattern: ^(Managed|Unmanaged|Force|Removed)$
type: string
type: object
type: object
type: object
status:
description: DataSciencePipelinesStatus defines the observed state of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,27 @@ spec:
type: object
type: array
type: object
managedPipelines:
properties:
instructLab:
description: |-
Configures whether to automatically import the InstructLab pipeline.
You must enable the trainingoperator component to run the InstructLab pipeline.
properties:
state:
default: Removed
description: |-
Set to one of the following values:

- "Managed" : This pipeline is automatically imported.
- "Removed" : This pipeline is not automatically imported when a new pipeline server or DSPA is created. If previously set to "Managed", setting to "Removed" does not remove existing preloaded pipelines but does prevent future updates from being imported.
enum:
- Managed
- Removed
pattern: ^(Managed|Unmanaged|Force|Removed)$
type: string
type: object
type: object
managementState:
description: |-
Set to one of the following values:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@ spec:
type: object
type: array
type: object
managedPipelines:
properties:
instructLab:
description: |-
Configures whether to automatically import the InstructLab pipeline.
You must enable the trainingoperator component to run the InstructLab pipeline.
properties:
state:
default: Removed
description: |-
Set to one of the following values:

- "Managed" : This pipeline is automatically imported.
- "Removed" : This pipeline is not automatically imported when a new pipeline server or DSPA is created. If previously set to "Managed", setting to "Removed" does not remove existing preloaded pipelines but does prevent future updates from being imported.
enum:
- Managed
- Removed
pattern: ^(Managed|Unmanaged|Force|Removed)$
type: string
type: object
type: object
type: object
status:
description: DataSciencePipelinesStatus defines the observed state of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,27 @@ spec:
type: object
type: array
type: object
managedPipelines:
properties:
instructLab:
description: |-
Configures whether to automatically import the InstructLab pipeline.
You must enable the trainingoperator component to run the InstructLab pipeline.
properties:
state:
default: Removed
description: |-
Set to one of the following values:

- "Managed" : This pipeline is automatically imported.
- "Removed" : This pipeline is not automatically imported when a new pipeline server or DSPA is created. If previously set to "Managed", setting to "Removed" does not remove existing preloaded pipelines but does prevent future updates from being imported.
enum:
- Managed
- Removed
pattern: ^(Managed|Unmanaged|Force|Removed)$
type: string
type: object
type: object
managementState:
description: |-
Set to one of the following values:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
dscv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/controllers/status"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
cr "github.com/opendatahub-io/opendatahub-operator/v2/pkg/componentsregistry"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/annotations"
Expand All @@ -38,15 +39,21 @@
}

func (s *componentHandler) Init(_ common.Platform) error {
if err := deploy.ApplyParams(paramsPath().String(), imageParamMap); err != nil {
return fmt.Errorf("failed to update images on path %s: %w", paramsPath(), err)
release := cluster.GetRelease()

extraParams := map[string]string{
platformVersionParamsKey: release.Version.String(),
}

if err := deploy.ApplyParams(paramsPath, imageParamMap, extraParams); err != nil {
return fmt.Errorf("failed to apply params on path %s: %w", paramsPath, err)

Check warning on line 49 in controllers/components/datasciencepipelines/datasciencepipelines.go

View check run for this annotation

Codecov / codecov/patch

controllers/components/datasciencepipelines/datasciencepipelines.go#L42-L49

Added lines #L42 - L49 were not covered by tests
}

return nil
}

func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) common.PlatformObject {
return &componentApi.DataSciencePipelines{
obj := componentApi.DataSciencePipelines{

Check warning on line 56 in controllers/components/datasciencepipelines/datasciencepipelines.go

View check run for this annotation

Codecov / codecov/patch

controllers/components/datasciencepipelines/datasciencepipelines.go#L56

Added line #L56 was not covered by tests
TypeMeta: metav1.TypeMeta{
Kind: componentApi.DataSciencePipelinesKind,
APIVersion: componentApi.GroupVersion.String(),
Expand All @@ -61,6 +68,14 @@
DataSciencePipelinesCommonSpec: dsc.Spec.Components.DataSciencePipelines.DataSciencePipelinesCommonSpec,
},
}

// since the nested structures are not pointers, we must make sure
// any field respect the validation rules.
if obj.Spec.PreloadedPipelines.InstructLab.State == "" {
obj.Spec.PreloadedPipelines.InstructLab.State = operatorv1.Removed
}

Check warning on line 76 in controllers/components/datasciencepipelines/datasciencepipelines.go

View check run for this annotation

Codecov / codecov/patch

controllers/components/datasciencepipelines/datasciencepipelines.go#L71-L76

Added lines #L71 - L76 were not covered by tests

return &obj

Check warning on line 78 in controllers/components/datasciencepipelines/datasciencepipelines.go

View check run for this annotation

Codecov / codecov/patch

controllers/components/datasciencepipelines/datasciencepipelines.go#L78

Added line #L78 was not covered by tests
}

func (s *componentHandler) UpdateDSCStatus(dsc *dscv1.DataScienceCluster, obj client.Object) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,16 @@
}

func initialize(_ context.Context, rr *odhtypes.ReconciliationRequest) error {
rr.Manifests = append(rr.Manifests, manifestPath(rr.Release.Name))
rr.Manifests = []odhtypes.ManifestInfo{manifestPath(rr.Release.Name)}

extraParamsMap, err := computeParamsMap(rr)
if err != nil {
return fmt.Errorf("computing extra params failed: %w", err)
}

Check warning on line 78 in controllers/components/datasciencepipelines/datasciencepipelines_controller_actions.go

View check run for this annotation

Codecov / codecov/patch

controllers/components/datasciencepipelines/datasciencepipelines_controller_actions.go#L73-L78

Added lines #L73 - L78 were not covered by tests

if err := odhdeploy.ApplyParams(paramsPath, nil, extraParamsMap); err != nil {
return fmt.Errorf("failed to update params.env from %s : %w", paramsPath, err)
}

Check warning on line 82 in controllers/components/datasciencepipelines/datasciencepipelines_controller_actions.go

View check run for this annotation

Codecov / codecov/patch

controllers/components/datasciencepipelines/datasciencepipelines_controller_actions.go#L80-L82

Added lines #L80 - L82 were not covered by tests

return nil
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package datasciencepipelines

import (
"encoding/json"
"fmt"
"path"

conditionsv1 "github.com/openshift/custom-resource-status/conditions/v1"

"github.com/opendatahub-io/opendatahub-operator/v2/apis/common"
Expand All @@ -21,6 +25,9 @@
// via Kustomize. Since a deployment selector is immutable, we can't upgrade existing
// deployment to the new component name, so keep it around till we figure out a solution.
LegacyComponentName = "data-science-pipelines-operator"

managedPipelineParamsKey = "MANAGEDPIPELINES"
platformVersionParamsKey = "PLATFORMVERSION"
)

var (
Expand All @@ -42,20 +49,37 @@
cluster.OpenDataHub: "overlays/odh",
cluster.Unknown: "overlays/odh",
}

paramsPath = path.Join(odhdeploy.DefaultManifestPath, ComponentName, "base")
)

func paramsPath() types.ManifestInfo {
func manifestPath(p common.Platform) types.ManifestInfo {

Check warning on line 56 in controllers/components/datasciencepipelines/datasciencepipelines_support.go

View check run for this annotation

Codecov / codecov/patch

controllers/components/datasciencepipelines/datasciencepipelines_support.go#L56

Added line #L56 was not covered by tests
return types.ManifestInfo{
Path: odhdeploy.DefaultManifestPath,
ContextDir: ComponentName,
SourcePath: "base",
SourcePath: overlaysSourcePaths[p],

Check warning on line 60 in controllers/components/datasciencepipelines/datasciencepipelines_support.go

View check run for this annotation

Codecov / codecov/patch

controllers/components/datasciencepipelines/datasciencepipelines_support.go#L60

Added line #L60 was not covered by tests
}
}

func manifestPath(p common.Platform) types.ManifestInfo {
return types.ManifestInfo{
Path: odhdeploy.DefaultManifestPath,
ContextDir: ComponentName,
SourcePath: overlaysSourcePaths[p],
func computeParamsMap(rr *types.ReconciliationRequest) (map[string]string, error) {
dsp, ok := rr.Instance.(*componentApi.DataSciencePipelines)
if !ok {
return nil, fmt.Errorf("resource instance %v is not a componentApi.DataSciencePipelines", rr.Instance)
}

Check warning on line 68 in controllers/components/datasciencepipelines/datasciencepipelines_support.go

View check run for this annotation

Codecov / codecov/patch

controllers/components/datasciencepipelines/datasciencepipelines_support.go#L67-L68

Added lines #L67 - L68 were not covered by tests

data, err := json.Marshal(dsp.Spec.PreloadedPipelines)
if err != nil {
return nil, fmt.Errorf("marshalling preloaded pipelines failed: %w", err)
}

Check warning on line 73 in controllers/components/datasciencepipelines/datasciencepipelines_support.go

View check run for this annotation

Codecov / codecov/patch

controllers/components/datasciencepipelines/datasciencepipelines_support.go#L72-L73

Added lines #L72 - L73 were not covered by tests

data, err = json.Marshal(string(data))
if err != nil {
return nil, fmt.Errorf("marshalling preloaded pipelines failed: %w", err)
}

Check warning on line 78 in controllers/components/datasciencepipelines/datasciencepipelines_support.go

View check run for this annotation

Codecov / codecov/patch

controllers/components/datasciencepipelines/datasciencepipelines_support.go#L77-L78

Added lines #L77 - L78 were not covered by tests

extraParamsMap := map[string]string{
managedPipelineParamsKey: string(data),
}

return extraParamsMap, nil
}
Loading