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

kustomize renderer pipeline #14

Closed
Closed
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 apis/components/v1/dashboard_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ type DashboardSpec struct {
// DashboardStatus defines the observed state of Dashboard
type DashboardStatus struct {
components.Status `json:",inline"`

Namespace string `json:"namespace,omitempty"`
URL string `json:"url,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/components.opendatahub.io_dashboards.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,15 @@ spec:
- type
type: object
type: array
namespace:
type: string
observedGeneration:
format: int64
type: integer
phase:
type: string
url:
type: string
required:
- phase
type: object
Expand Down
107 changes: 107 additions & 0 deletions controllers/components/dashboard/dashboard_actions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package dashboard

import (
"context"
"errors"
"fmt"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
logf "sigs.k8s.io/controller-runtime/pkg/log"

componentsv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/components/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
odhtypes "github.com/opendatahub-io/opendatahub-operator/v2/pkg/controller/types"
odhdeploy "github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
)

func initialize(ctx context.Context, rr *odhtypes.ReconciliationRequest) error {
// Implement initialization logic
log := logf.FromContext(ctx).WithName(ComponentNameUpstream)

rr.Manifests = []odhtypes.ManifestInfo{defaultManifestInfo(rr.Platform)}

if err := odhdeploy.ApplyParams(rr.Manifests[0].ManifestsPath(), imagesMap); err != nil {
log.Error(err, "failed to update image", "path", rr.Manifests[0].ManifestsPath())
}

extraParamsMap, err := updateKustomizeVariable(ctx, rr.Client, rr.Platform, &rr.DSCI.Spec)
if err != nil {
return errors.New("failed to set variable for extraParamsMap")
}

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

// TODO: this should probably be moved to an higher level, added here
// mainly for convenience since the route url is determined at
// this stage
d, ok := rr.Instance.(*componentsv1.Dashboard)
if !ok {
return fmt.Errorf("instance is not of type *odhTypes.Dashboard")
}

d.Status.Namespace = rr.DSCI.Spec.ApplicationsNamespace
d.Status.URL = extraParamsMap["dashboard-url"]

return nil
}

func devFlags(ctx context.Context, rr *odhtypes.ReconciliationRequest) error {
dashboard, ok := rr.Instance.(*componentsv1.Dashboard)
if !ok {
return fmt.Errorf("resource instance %v is not a componentsv1.Dashboard)", rr.Instance)
}

if dashboard.Spec.DevFlags == nil {
return nil
}
// Implement devflags support logic
// If dev flags are set, update default manifests path
if len(dashboard.Spec.DevFlags.Manifests) != 0 {
manifestConfig := dashboard.Spec.DevFlags.Manifests[0]
if err := odhdeploy.DownloadManifests(ctx, ComponentNameUpstream, manifestConfig); err != nil {
return err
}
if manifestConfig.SourcePath != "" {
rr.Manifests[0].Path = odhdeploy.DefaultManifestPath
rr.Manifests[0].ContextDir = ComponentNameUpstream
rr.Manifests[0].SourcePath = manifestConfig.SourcePath
}
}

return nil
}

func customizeResources(ctx context.Context, rr *odhtypes.ReconciliationRequest) error {
switch rr.Platform {
case cluster.SelfManagedRhods, cluster.ManagedRhods:
if err := cluster.UpdatePodSecurityRolebinding(ctx, rr.Client, rr.DSCI.Spec.ApplicationsNamespace, "rhods-dashboard"); err != nil {
return fmt.Errorf("failed to update PodSecurityRolebinding for rhods-dashboard: %w", err)
}

err := rr.AddResource(&corev1.Secret{
TypeMeta: metav1.TypeMeta{
APIVersion: corev1.SchemeGroupVersion.String(),
Kind: "Secret",
},
ObjectMeta: metav1.ObjectMeta{
Name: "anaconda-ce-access",
Namespace: rr.DSCI.Spec.ApplicationsNamespace,
},
Type: corev1.SecretTypeOpaque,
})

if err != nil {
return fmt.Errorf("failed to create access-secret for anaconda: %w", err)
}

default:
if err := cluster.UpdatePodSecurityRolebinding(ctx, rr.Client, rr.DSCI.Spec.ApplicationsNamespace, "odh-dashboard"); err != nil {
return fmt.Errorf("failed to update PodSecurityRolebinding for odh-dashboard: %w", err)
}
}

return nil
}
Loading