Skip to content

Commit

Permalink
Unset Tech Preview components by default (opendatahub-io#708)
Browse files Browse the repository at this point in the history
* Unset Tech Preview components by default

* Update default DSC and DSCI name
  • Loading branch information
VaishnaviHire authored Nov 9, 2023
1 parent 86aad1c commit 1ccbe05
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ metadata:
"app.kubernetes.io/name": "datasciencecluster",
"app.kubernetes.io/part-of": "opendatahub-operator"
},
"name": "default"
"name": "default-dsc"
},
"spec": {
"components": {
Expand Down Expand Up @@ -57,7 +57,7 @@ metadata:
"app.kubernetes.io/name": "dscinitialization",
"app.kubernetes.io/part-of": "opendatahub-operator"
},
"name": "default"
"name": "default-dsci"
},
"spec": {
"applicationsNamespace": "opendatahub",
Expand Down
20 changes: 0 additions & 20 deletions config/samples/console_v1_odhquickstarts.yaml

This file was deleted.

20 changes: 0 additions & 20 deletions config/samples/dashboard_v1_odhapplications.yaml

This file was deleted.

16 changes: 0 additions & 16 deletions config/samples/dashboard_v1_odhdocuments.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: datasciencecluster.opendatahub.io/v1
kind: DataScienceCluster
metadata:
name: default
name: default-dsc
labels:
app.kubernetes.io/name: datasciencecluster
app.kubernetes.io/instance: default
Expand Down
2 changes: 1 addition & 1 deletion config/samples/dscinitialization_v1_dscinitialization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ metadata:
app.kubernetes.io/part-of: opendatahub-operator
app.kubernetes.io/managed-by: kustomize
app.kubernetes.io/created-by: opendatahub-operator
name: default
name: default-dsci
spec:
monitoring:
managementState: "Managed"
Expand Down
4 changes: 0 additions & 4 deletions config/samples/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@ kind: Kustomization
resources:
- datasciencecluster_v1_datasciencecluster.yaml
- dscinitialization_v1_dscinitialization.yaml
- opendatahub_v1alpha1_odhdashboardconfigs.yaml
- dashboard_v1_odhdocuments.yaml
- dashboard_v1_odhapplications.yaml
- console_v1_odhquickstarts.yaml
#+kubebuilder:scaffold:manifestskustomizesamples
21 changes: 0 additions & 21 deletions config/samples/opendatahub_v1alpha1_odhdashboardconfigs.yaml

This file was deleted.

27 changes: 6 additions & 21 deletions controllers/dscinitialization/dscinitialization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,33 +83,18 @@ func (r *DSCInitializationReconciler) Reconcile(ctx context.Context, req ctrl.Re
return ctrl.Result{}, err
}

if len(instances.Items) > 1 {
// check if multiple instances of DSCInitialization, exit with error
message := fmt.Sprintf("only one instance of DSCInitialization object is allowed. Update existing instance name %s", req.Name)

return ctrl.Result{}, errors.New(message)
}

if len(instances.Items) == 0 {
// DSCInitialization instance not found
var instance *dsciv1.DSCInitialization
switch {
case len(instances.Items) == 0:
return ctrl.Result{}, nil
}

instance := &instances.Items[0]
if instance.Name != "default" {
message := fmt.Sprintf("Should update existing instance name %s to 'default'", instance.Name)

return ctrl.Result{}, errors.New(message)
}

if len(instances.Items) > 1 {
case len(instances.Items) == 1:
instance = &instances.Items[0]
case len(instances.Items) > 1:
message := fmt.Sprintf("only one instance of DSCInitialization object is allowed. Update existing instance name %s", req.Name)

_, _ = r.updateStatus(ctx, instance, func(saved *dsciv1.DSCInitialization) {
status.SetErrorCondition(&saved.Status.Conditions, status.DuplicateDSCInitialization, message)
saved.Status.Phase = status.PhaseError
})

return ctrl.Result{}, errors.New(message)
}

Expand Down
18 changes: 3 additions & 15 deletions controllers/dscinitialization/dscinitialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const (
var _ = Describe("DataScienceCluster initialization", func() {
Context("Creation of related resources", func() {
// must be default as instance name, or it will break
const applicationName = "default"
const applicationName = "default-dsci"
BeforeEach(func() {
// when
desiredDsci := createDSCI(applicationName, operatorv1.Managed, monitoringNamespace)
Expand Down Expand Up @@ -92,7 +92,7 @@ var _ = Describe("DataScienceCluster initialization", func() {
Context("Monitoring Resource", func() {
AfterEach(cleanupResources)
const monitoringNamespace2 = "test-monitoring-ns2"
const applicationName = "default"
const applicationName = "default-dsci"
It("Should not create monitoring namespace if monitoring is disabled", func() {
// when
desiredDsci := createDSCI(applicationName, operatorv1.Removed, monitoringNamespace2)
Expand All @@ -118,19 +118,7 @@ var _ = Describe("DataScienceCluster initialization", func() {

Context("Handling existing resources", func() {
AfterEach(cleanupResources)
const applicationName = "default"

It("Should not create DSCI instance if name not 'default'", func() {
wrongApplicationName := "default2"
// when
desiredDsci := createDSCI(wrongApplicationName, operatorv1.Managed, monitoringNamespace)
Expect(k8sClient.Create(context.Background(), desiredDsci)).Should(Succeed())
foundDsciList := &dsci.DSCInitializationList{}

// then
Expect(len(foundDsciList.Items)).To(Equal(0))
Eventually(dscInitializationIsReady(wrongApplicationName, workingNamespace, desiredDsci), timeout, interval).Should(BeFalse())
})
const applicationName = "default-dsci"

It("Should not have more than one DSCI instance in the cluster", func() {

Expand Down
57 changes: 9 additions & 48 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ limitations under the License.
package main

import (
"context"
"encoding/json"
"flag"
"os"

addonv1alpha1 "github.com/openshift/addon-operator/apis/addons/v1alpha1"
ocv1 "github.com/openshift/api/oauth/v1"
operatorv1 "github.com/openshift/api/operator/v1"
routev1 "github.com/openshift/api/route/v1"
ocuserv1 "github.com/openshift/api/user/v1"
ofapiv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
Expand All @@ -34,10 +31,7 @@ import (
netv1 "k8s.io/api/networking/v1"
authv1 "k8s.io/api/rbac/v1"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -162,48 +156,6 @@ func main() { //nolint:funlen
os.Exit(1)
}

// Check if user opted for disabling DSC configuration
_, disableDSCConfig := os.LookupEnv("DISABLE_DSC_CONFIG")
if !disableDSCConfig {
// Create DSCInitialization CR if it's not present
c := mgr.GetClient()
releaseDscInitialization := &dsci.DSCInitialization{
TypeMeta: metav1.TypeMeta{
Kind: "DSCInitialization",
APIVersion: "dscinitialization.opendatahub.io/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "default",
},
Spec: dsci.DSCInitializationSpec{
ApplicationsNamespace: dscApplicationsNamespace,
Monitoring: dsci.Monitoring{
ManagementState: operatorv1.Managed,
Namespace: dscMonitoringNamespace,
},
},
}
err = c.Create(context.TODO(), releaseDscInitialization)
switch {
case err == nil:
setupLog.Info("created DscInitialization resource")
case errors.IsAlreadyExists(err):
// Update if already exists
setupLog.Info("DscInitialization resource already exists. Updating it.")
data, err := json.Marshal(releaseDscInitialization)
if err != nil {
setupLog.Error(err, "failed to get DscInitialization custom resource data")
}
err = c.Patch(context.TODO(), releaseDscInitialization, client.RawPatch(types.ApplyPatchType, data),
client.ForceOwnership, client.FieldOwner("opendatahub-operator"))
if err != nil {
setupLog.Error(err, "failed to update DscInitialization custom resource")
}
default:
setupLog.Error(err, "failed to create DscInitialization custom resource")
os.Exit(1)
}
}
// Create new uncached client to run initial setup
setupCfg, err := config.GetConfig()
if err != nil {
Expand All @@ -223,6 +175,15 @@ func main() { //nolint:funlen
os.Exit(1)
}

// Check if user opted for disabling DSC configuration
_, disableDSCConfig := os.LookupEnv("DISABLE_DSC_CONFIG")
if !disableDSCConfig {
if err = upgrade.CreateDefaultDSCI(setupClient, platform, dscApplicationsNamespace, dscMonitoringNamespace); err != nil {
setupLog.Error(err, "unable to create initial setup for the operator")
os.Exit(1)
}
}

// Apply update from legacy operator
if err = upgrade.UpdateFromLegacyVersion(setupClient, platform); err != nil {
setupLog.Error(err, "unable to update from legacy operator version")
Expand Down
Loading

0 comments on commit 1ccbe05

Please sign in to comment.