Skip to content

Commit

Permalink
Add configuration to pipeline stanza of DSC to enable InstructLab pip…
Browse files Browse the repository at this point in the history
…eline
  • Loading branch information
lburgazzoli committed Jan 9, 2025
1 parent 2eea4f1 commit c19f08f
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 12 deletions.
21 changes: 21 additions & 0 deletions apis/components/v1alpha1/datasciencepipelines/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// +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 PreloadedPipelinesSpec struct {
InstructLab InstructLabPipelineSpec `json:"instructLab,omitempty"`
}

type InstructLabPipelineSpec struct {
// Set to one of the following values:
//
// - "Managed" : TODO
// - "Removed" : TODO
//
// +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.PreloadedPipelinesSpec `json:"preloadedPipelines,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,24 @@ spec:
type: object
type: array
type: object
preloadedPipelines:
properties:
instructLab:
properties:
state:
default: Removed
description: |-
Set to one of the following values:
- "Managed" : TODO
- "Removed" : TODO
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 @@ -186,6 +186,24 @@ spec:
- Removed
pattern: ^(Managed|Unmanaged|Force|Removed)$
type: string
preloadedPipelines:
properties:
instructLab:
properties:
state:
default: Removed
description: |-
Set to one of the following values:
- "Managed" : TODO
- "Removed" : TODO
enum:
- Managed
- Removed
pattern: ^(Managed|Unmanaged|Force|Removed)$
type: string
type: object
type: object
type: object
kserve:
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,24 @@ spec:
type: object
type: array
type: object
preloadedPipelines:
properties:
instructLab:
properties:
state:
default: Removed
description: |-
Set to one of the following values:
- "Managed" : TODO
- "Removed" : TODO
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 @@ -186,6 +186,24 @@ spec:
- Removed
pattern: ^(Managed|Unmanaged|Force|Removed)$
type: string
preloadedPipelines:
properties:
instructLab:
properties:
state:
default: Removed
description: |-
Set to one of the following values:
- "Managed" : TODO
- "Removed" : TODO
enum:
- Managed
- Removed
pattern: ^(Managed|Unmanaged|Force|Removed)$
type: string
type: object
type: object
type: object
kserve:
description: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ func (s *componentHandler) GetManagementState(dsc *dscv1.DataScienceCluster) ope
}

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

return nil
}

func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) common.PlatformObject {
return &componentApi.DataSciencePipelines{
obj := componentApi.DataSciencePipelines{
TypeMeta: metav1.TypeMeta{
Kind: componentApi.DataSciencePipelinesKind,
APIVersion: componentApi.GroupVersion.String(),
Expand All @@ -62,6 +62,14 @@ func (s *componentHandler) NewCRObject(dsc *dscv1.DataScienceCluster) common.Pla
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
}

return &obj
}

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 @@ -18,6 +18,7 @@ package datasciencepipelines

import (
"context"
"encoding/json"
"fmt"

apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
Expand Down Expand Up @@ -70,7 +71,25 @@ func checkPreConditions(ctx context.Context, rr *odhtypes.ReconciliationRequest)
}

func initialize(_ context.Context, rr *odhtypes.ReconciliationRequest) error {
rr.Manifests = append(rr.Manifests, manifestPath(rr.Release.Name))
dsp, ok := rr.Instance.(*componentApi.DataSciencePipelines)
if !ok {
return fmt.Errorf("resource instance %v is not a componentApi.DataSciencePipelines", rr.Instance)
}

rr.Manifests = []odhtypes.ManifestInfo{manifestPath(rr.Release.Name)}

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

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

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

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

import (
"path"

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

componentApi "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1"
Expand Down Expand Up @@ -48,15 +50,9 @@ var (
cluster.OpenDataHub: "overlays/odh",
cluster.Unknown: "overlays/odh",
}
)

func paramsPath() types.ManifestInfo {
return types.ManifestInfo{
Path: odhdeploy.DefaultManifestPath,
ContextDir: ComponentName,
SourcePath: "base",
}
}
paramsPath = path.Join(odhdeploy.DefaultManifestPath, ComponentName, "base")
)

func manifestPath(p cluster.Platform) types.ManifestInfo {
return types.ManifestInfo{
Expand Down
3 changes: 3 additions & 0 deletions docs/api-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ _Appears in:_
| --- | --- | --- | --- |
| `managementState` _[ManagementState](#managementstate)_ | Set to one of the following values:<br /><br />- "Managed" : the operator is actively managing the component and trying to keep it active.<br /> It will only upgrade the component if it is safe to do so<br /><br />- "Removed" : the operator is actively managing the component and will not install it,<br /> or if it is installed, the operator will try to remove it | | Enum: [Managed Removed] <br /> |
| `devFlags` _[DevFlags](#devflags)_ | Add developer fields | | |
| `preloadedPipelines` _[PreloadedPipelinesSpec](#preloadedpipelinesspec)_ | | | |


#### DSCDataSciencePipelinesStatus
Expand Down Expand Up @@ -661,6 +662,7 @@ _Appears in:_
| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `devFlags` _[DevFlags](#devflags)_ | Add developer fields | | |
| `preloadedPipelines` _[PreloadedPipelinesSpec](#preloadedpipelinesspec)_ | | | |


#### DataSciencePipelinesCommonStatus
Expand Down Expand Up @@ -711,6 +713,7 @@ _Appears in:_
| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `devFlags` _[DevFlags](#devflags)_ | Add developer fields | | |
| `preloadedPipelines` _[PreloadedPipelinesSpec](#preloadedpipelinesspec)_ | | | |


#### DataSciencePipelinesStatus
Expand Down
8 changes: 8 additions & 0 deletions tests/e2e/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package e2e_test
import (
"context"
"fmt"
"github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1alpha1/datasciencepipelines"

Check failure on line 6 in tests/e2e/helper_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

File is not properly formatted (gci)
"log"
"strings"
"testing"
Expand Down Expand Up @@ -155,6 +156,13 @@ func setupDSCInstance(name string) *dscv1.DataScienceCluster {
ManagementSpec: common.ManagementSpec{
ManagementState: operatorv1.Removed,
},
DataSciencePipelinesCommonSpec: componentApi.DataSciencePipelinesCommonSpec{
PreloadedPipelines: datasciencepipelines.PreloadedPipelinesSpec{
InstructLab: datasciencepipelines.InstructLabPipelineSpec{
State: operatorv1.Removed,
},
},
},
},
Kserve: componentApi.DSCKserve{
ManagementSpec: common.ManagementSpec{
Expand Down

0 comments on commit c19f08f

Please sign in to comment.