Skip to content

Commit

Permalink
update(dsci): do not create default DSCI CR if it is running in ODH (o…
Browse files Browse the repository at this point in the history
…pendatahub-io#770)

* update(dsci): do not create default DSCI CR if it is ODH

- the change is done without code logic but only set the env varible
   DISABLE_DSC_CONFIG in the CSV
- to keep the old logic (let operator auto create DSCI CR): remove this variable from CSV and restart pod. OR use API to not set this variable in subscription

* cleanup: initialization-resource in CSV

- since we do not create DSCI CR automatically, should not have required
on DSC CR

* test(e2e): add test for DSCI CR

---------

Signed-off-by: Wen Zhou <wenzhou@redhat.com>
  • Loading branch information
zdtsw authored Jan 12, 2024
1 parent 918055b commit 6e37c08
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 101 deletions.
33 changes: 30 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ and installed from source manually, see the Developer guide for further instruct
EOF
```

2. Create [DataScienceCluster](#example-datasciencecluster) CR to enable components
2. Create [DSCInitializationc](#example-dscinitialization) CR manually.
You can also use operator to create default DSCI CR by removing env variable DISABLE_DSC_CONFIG from CSV following restart operator pod.

3. Create [DataScienceCluster](#example-datasciencecluster) CR to enable components

## Dev Preview

Expand Down Expand Up @@ -195,7 +198,31 @@ There are 2 ways to test your changes with modification:

1. set `devFlags.ManifestsUri` field of DSCI instance during runtime: this will pull down manifests from remote git repo
by using this method, it overwrites manifests and component images if images are set in the params.env file
2. [Under implementation] build operator image with local manifests
2. [Under implementation] build operator image with local manifests.

### Example DSCInitialization

Below is the default DSCI CR config

```console
apiVersion: dscinitialization.opendatahub.io/v1
kind: DSCInitialization
metadata:
name: default-dsci
spec:
applicationsNamespace: opendatahub
monitoring:
managementState: Managed
namespace: opendatahub
serviceMesh:
controlPlane:
metricsCollection: Istio
name: data-science-smcp
namespace: istio-system
managementState: Managed
```

Apply this example with modification for your usage.

### Example DataScienceCluster

Expand All @@ -208,7 +235,7 @@ components. At a given time, ODH supports only **one** instance of the CR, which
apiVersion: datasciencecluster.opendatahub.io/v1
kind: DataScienceCluster
metadata:
name: example
name: default-dsc
spec:
components:
codeflare:
Expand Down
46 changes: 3 additions & 43 deletions bundle/manifests/opendatahub-operator.clusterserviceversion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,49 +105,6 @@ metadata:
containerImage: quay.io/opendatahub/opendatahub-operator:v2.1.0
createdAt: "2023-8-23T00:00:00Z"
olm.skipRange: '>=1.0.0 <2.0.0'
operatorframework.io/initialization-resource: |-
{
"apiVersion": "datasciencecluster.opendatahub.io/v1",
"kind": "DataScienceCluster",
"metadata": {
"name": "default",
"labels": {
"app.kubernetes.io/name": "datasciencecluster",
"app.kubernetes.io/instance": "default",
"app.kubernetes.io/part-of": "opendatahub-operator",
"app.kubernetes.io/managed-by": "kustomize",
"app.kubernetes.io/created-by": "opendatahub-operator"
}
},
"spec": {
"components": {
"codeflare": {
"managementState": "Removed"
},
"dashboard": {
"managementState": "Managed"
},
"datasciencepipelines": {
"managementState": "Managed"
},
"kserve": {
"managementState": "Removed"
},
"modelmeshserving": {
"managementState": "Managed"
},
"ray": {
"managementState": "Removed"
},
"workbenches": {
"managementState": "Managed"
},
"trustyai": {
"managementState": "Removed"
}
}
}
}
operators.operatorframework.io/builder: operator-sdk-v1.24.1
operators.operatorframework.io/internal-objects: '[dscinitialization.opendatahub.io]'
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
Expand Down Expand Up @@ -1747,6 +1704,9 @@ spec:
- --leader-elect
command:
- /manager
env:
- name: DISABLE_DSC_CONFIG
value: "true"
image: REPLACE_IMAGE:latest
imagePullPolicy: Always
livenessProbe:
Expand Down
3 changes: 3 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ spec:
containers:
- command:
- /manager
env:
- name: DISABLE_DSC_CONFIG
value: 'true'
args:
- --leader-elect
image: controller:latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,6 @@ metadata:
containerImage: quay.io/opendatahub/opendatahub-operator:v2.1.0
createdAt: "2023-8-23T00:00:00Z"
olm.skipRange: '>=1.0.0 <2.0.0'
operatorframework.io/initialization-resource: |-
{
"apiVersion": "datasciencecluster.opendatahub.io/v1",
"kind": "DataScienceCluster",
"metadata": {
"name": "default",
"labels": {
"app.kubernetes.io/name": "datasciencecluster",
"app.kubernetes.io/instance": "default",
"app.kubernetes.io/part-of": "opendatahub-operator",
"app.kubernetes.io/managed-by": "kustomize",
"app.kubernetes.io/created-by": "opendatahub-operator"
}
},
"spec": {
"components": {
"codeflare": {
"managementState": "Removed"
},
"dashboard": {
"managementState": "Managed"
},
"datasciencepipelines": {
"managementState": "Managed"
},
"kserve": {
"managementState": "Removed"
},
"modelmeshserving": {
"managementState": "Managed"
},
"ray": {
"managementState": "Removed"
},
"workbenches": {
"managementState": "Managed"
},
"trustyai": {
"managementState": "Removed"
}
}
}
}
operators.operatorframework.io/internal-objects: '[dscinitialization.opendatahub.io]'
repository: https://github.com/opendatahub-io/opendatahub-operator
name: opendatahub-operator.v0.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ func (r *DataScienceClusterReconciler) Reconcile(ctx context.Context, req ctrl.R
switch len(dsciInstances.Items) {
case 0:
reason := status.ReconcileFailed
message := "Failed to get a valid DSCInitialization instance"
message := "Failed to get a valid DSCInitialization instance, please create a DSCI instance"
r.Log.Info(message)
instance, err = r.updateStatus(ctx, instance, func(saved *dsc.DataScienceCluster) {
status.SetProgressingCondition(&saved.Status.Conditions, reason, message)
saved.Status.Phase = status.PhaseError
Expand Down
15 changes: 6 additions & 9 deletions tests/e2e/controller_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
autoscalingv1 "k8s.io/api/autoscaling/v1"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
k8sclient "k8s.io/client-go/kubernetes"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
Expand Down Expand Up @@ -49,6 +48,8 @@ type testContext struct {
resourceCreationTimeout time.Duration
// test DataScienceCluster instance
testDsc *dsc.DataScienceCluster
// test DSCI CR because we do not create it in ODH by default
testDSCI *dsci.DSCInitialization
// time interval to check for resource creation
resourceRetryInterval time.Duration
// context for accessing resources
Expand All @@ -75,26 +76,22 @@ func NewTestContext() (*testContext, error) { //nolint:golint,revive // Only use
return nil, errors.Wrap(err, "failed to initialize custom client")
}

// setup DSCI CR since we do not create automatically by operator
testDSCI := setupDSCICR()
// Setup DataScienceCluster CR
testDSC := setupDSCInstance()

// Get Applications namespace from DSCInitialization instance
dscInit := &dsci.DSCInitialization{}
err = custClient.Get(context.TODO(), types.NamespacedName{Name: "default-dsci"}, dscInit)
if err != nil {
return nil, errors.Wrap(err, "error getting DSCInitialization instance")
}

return &testContext{
cfg: config,
kubeClient: kc,
customClient: custClient,
operatorNamespace: opNamespace,
applicationsNamespace: dscInit.Spec.ApplicationsNamespace,
applicationsNamespace: testDSCI.Spec.ApplicationsNamespace,
resourceCreationTimeout: time.Minute * 2,
resourceRetryInterval: time.Second * 10,
ctx: context.TODO(),
testDsc: testDSC,
testDSCI: testDSCI,
}, nil
}

Expand Down
44 changes: 43 additions & 1 deletion tests/e2e/dsc_creation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"k8s.io/client-go/util/retry"

dsc "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
dsci "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/components"
)

Expand All @@ -29,6 +30,10 @@ func creationTestSuite(t *testing.T) {
testCtx, err := NewTestContext()
require.NoError(t, err)
t.Run(testCtx.testDsc.Name, func(t *testing.T) {
t.Run("Creation of DSCI CR", func(t *testing.T) {
err = testCtx.testDSCICreation()
require.NoError(t, err, "error creating DSCI CR")
})
t.Run("Creation of DataScienceCluster instance", func(t *testing.T) {
err = testCtx.testDSCCreation()
require.NoError(t, err, "error creating DataScienceCluster instance")
Expand All @@ -53,7 +58,44 @@ func creationTestSuite(t *testing.T) {
})
}

func (tc *testContext) testDSCCreation() error {
func (tc *testContext) testDSCICreation() error { //nolint: dupl
dscLookupKey := types.NamespacedName{Name: tc.testDsc.Name}
createdDSCI := &dsci.DSCInitialization{}
existingDSCIList := &dsci.DSCInitializationList{}

err := tc.customClient.List(tc.ctx, existingDSCIList)
if err == nil {
// use what you have
if len(existingDSCIList.Items) == 1 {
tc.testDSCI = &existingDSCIList.Items[0]
return nil
}
}
// create one for you
err = tc.customClient.Get(tc.ctx, dscLookupKey, createdDSCI)
if err != nil {
if errors.IsNotFound(err) {
nberr := wait.PollUntilContextTimeout(tc.ctx, tc.resourceRetryInterval, tc.resourceCreationTimeout, false, func(ctx context.Context) (bool, error) {
creationErr := tc.customClient.Create(tc.ctx, tc.testDSCI)
if creationErr != nil {
log.Printf("error creating DSCI resource %v: %v, trying again",
tc.testDSCI.Name, creationErr)
return false, nil
}
return true, nil
})
if nberr != nil {
return fmt.Errorf("error creating e2e-test-dsci DSCI CR %s: %w", tc.testDSCI.Name, nberr)
}
} else {
return fmt.Errorf("error getting e2e-test-dsci DSCI CR %s: %w", tc.testDSCI.Name, err)
}
}

return nil
}

func (tc *testContext) testDSCCreation() error { //nolint: dupl
// Create DataScienceCluster resource if not already created

dscLookupKey := types.NamespacedName{Name: tc.testDsc.Name}
Expand Down
19 changes: 18 additions & 1 deletion tests/e2e/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

dsc "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
dsci "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/components"
"github.com/opendatahub-io/opendatahub-operator/v2/components/codeflare"
"github.com/opendatahub-io/opendatahub-operator/v2/components/dashboard"
Expand Down Expand Up @@ -53,10 +54,26 @@ func (tc *testContext) waitForControllerDeployment(name string, replicas int32)
return err
}

func setupDSCICR() *dsci.DSCInitialization {
dsciTest := &dsci.DSCInitialization{
ObjectMeta: metav1.ObjectMeta{
Name: "e2e-test-dsci",
},
Spec: dsci.DSCInitializationSpec{
ApplicationsNamespace: "opendatahub",
Monitoring: dsci.Monitoring{
ManagementState: "Managed",
Namespace: "opendatahub",
},
},
}
return dsciTest
}

func setupDSCInstance() *dsc.DataScienceCluster {
dscTest := &dsc.DataScienceCluster{
ObjectMeta: metav1.ObjectMeta{
Name: "e2e-test",
Name: "e2e-test-dsc",
},
Spec: dsc.DataScienceClusterSpec{
Components: dsc.Components{
Expand Down

0 comments on commit 6e37c08

Please sign in to comment.