Skip to content

Commit

Permalink
Revert "chore(cleanup): remove checkDependentOperators as duplicated …
Browse files Browse the repository at this point in the history
…logic (opendatahub-io#996)" (opendatahub-io#1107)

This reverts commit 55320b6.
  • Loading branch information
zdtsw authored and bartoszmajsak committed Jul 10, 2024
1 parent e12d7d7 commit 8d2da19
Show file tree
Hide file tree
Showing 39 changed files with 1,429 additions and 691 deletions.
1 change: 1 addition & 0 deletions apis/features/v1/features_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ var ConditionReason = struct {
const (
ComponentType OwnerType = "Component"
DSCIType OwnerType = "DSCI"
UnknownType OwnerType = "Unknown"
)

func (s *FeatureTracker) ToOwnerReference() metav1.OwnerReference {
Expand Down
2 changes: 1 addition & 1 deletion components/kserve/kserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (k *Kserve) ReconcileComponent(ctx context.Context, cli client.Client,
}
} else {
// Configure dependencies
if err := k.configureServerless(ctx, dscispec); err != nil {
if err := k.configureServerless(ctx, cli, dscispec); err != nil {
return err
}
if k.DevFlags != nil {
Expand Down
35 changes: 32 additions & 3 deletions components/kserve/kserve_config_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import (
"errors"
"fmt"

"github.com/hashicorp/go-multierror"
operatorv1 "github.com/openshift/api/operator/v1"
corev1 "k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/feature"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/metadata/labels"
)
Expand Down Expand Up @@ -115,7 +117,7 @@ func (k *Kserve) setDefaultDeploymentMode(ctx context.Context, cli client.Client
return nil
}

func (k *Kserve) configureServerless(ctx context.Context, instance *dsciv1.DSCInitializationSpec) error {
func (k *Kserve) configureServerless(ctx context.Context, cli client.Client, instance *dsciv1.DSCInitializationSpec) error {
switch k.Serving.ManagementState {
case operatorv1.Unmanaged: // Bring your own CR
fmt.Println("Serverless CR is not configured by the operator, we won't do anything")
Expand All @@ -132,7 +134,13 @@ func (k *Kserve) configureServerless(ctx context.Context, instance *dsciv1.DSCIn
return errors.New("ServiceMesh is need to set to 'Managed' in DSCI CR, it is required by KServe serving field")
}

serverlessFeatures := feature.ComponentFeaturesHandler(k.GetComponentName(), instance, k.configureServerlessFeatures())
// check on dependent operators if all installed in cluster
dependOpsErrors := checkDependentOperators(ctx, cli).ErrorOrNil()
if dependOpsErrors != nil {
return dependOpsErrors
}

serverlessFeatures := feature.ComponentFeaturesHandler(k.GetComponentName(), instance.ApplicationsNamespace, k.configureServerlessFeatures(instance))

if err := serverlessFeatures.Apply(ctx); err != nil {
return err
Expand All @@ -142,7 +150,28 @@ func (k *Kserve) configureServerless(ctx context.Context, instance *dsciv1.DSCIn
}

func (k *Kserve) removeServerlessFeatures(ctx context.Context, instance *dsciv1.DSCInitializationSpec) error {
serverlessFeatures := feature.ComponentFeaturesHandler(k.GetComponentName(), instance, k.configureServerlessFeatures())
serverlessFeatures := feature.ComponentFeaturesHandler(k.GetComponentName(), instance.ApplicationsNamespace, k.configureServerlessFeatures(instance))

return serverlessFeatures.Delete(ctx)
}

func checkDependentOperators(ctx context.Context, cli client.Client) *multierror.Error {
var multiErr *multierror.Error

if found, err := cluster.OperatorExists(ctx, cli, ServiceMeshOperator); err != nil {
multiErr = multierror.Append(multiErr, err)
} else if !found {
err = fmt.Errorf("operator %s not found. Please install the operator before enabling %s component",
ServiceMeshOperator, ComponentName)
multiErr = multierror.Append(multiErr, err)
}

if found, err := cluster.OperatorExists(ctx, cli, ServerlessOperator); err != nil {
multiErr = multierror.Append(multiErr, err)
} else if !found {
err = fmt.Errorf("operator %s not found. Please install the operator before enabling %s component",
ServerlessOperator, ComponentName)
multiErr = multierror.Append(multiErr, err)
}
return multiErr
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ metadata:
namespace: {{ .ControlPlane.Namespace }}
spec:
provider:
name: {{ .AppNamespace }}-auth-provider
name: {{ .AuthExtensionName }}
67 changes: 27 additions & 40 deletions components/kserve/serverless_setup.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
package kserve

import (
"context"
"path"

dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/feature"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/feature/serverless"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/feature/servicemesh"
)

func (k *Kserve) configureServerlessFeatures() feature.FeaturesProvider {
return func(handler *feature.FeaturesHandler) error {
servingDeploymentErr := feature.CreateFeature("serverless-serving-deployment").
For(handler).
func (k *Kserve) configureServerlessFeatures(dsciSpec *dsciv1.DSCInitializationSpec) feature.FeaturesProvider {
return func(registry feature.FeaturesRegistry) error {
servingDeployment := feature.Define("serverless-serving-deployment").
ManifestsLocation(Resources.Location).
Manifests(
path.Join(Resources.InstallDir),
).
WithData(PopulateComponentSettings(k)).
WithData(
serverless.FeatureData.IngressDomain.Define(&k.Serving).AsAction(),
serverless.FeatureData.Serving.Define(&k.Serving).AsAction(),
servicemesh.FeatureData.ControlPlane.Define(dsciSpec).AsAction(),
).
PreConditions(
serverless.EnsureServerlessOperatorInstalled,
serverless.EnsureServerlessAbsent,
Expand All @@ -26,53 +29,37 @@ func (k *Kserve) configureServerlessFeatures() feature.FeaturesProvider {
).
PostConditions(
feature.WaitForPodsToBeReady(serverless.KnativeServingNamespace),
).
Load()
if servingDeploymentErr != nil {
return servingDeploymentErr
}
)

servingNetIstioSecretFilteringErr := feature.CreateFeature("serverless-net-istio-secret-filtering").
For(handler).
istioSecretFiltering := feature.Define("serverless-net-istio-secret-filtering").
ManifestsLocation(Resources.Location).
Manifests(
path.Join(Resources.BaseDir, "serving-net-istio-secret-filtering.patch.tmpl.yaml"),
).
WithData(PopulateComponentSettings(k)).
WithData(serverless.FeatureData.Serving.Define(&k.Serving).AsAction()).
PreConditions(serverless.EnsureServerlessServingDeployed).
PostConditions(
feature.WaitForPodsToBeReady(serverless.KnativeServingNamespace),
).
Load()
if servingNetIstioSecretFilteringErr != nil {
return servingNetIstioSecretFilteringErr
}
)

serverlessGwErr := feature.CreateFeature("serverless-serving-gateways").
For(handler).
PreConditions(serverless.EnsureServerlessServingDeployed).
WithData(
PopulateComponentSettings(k),
serverless.ServingDefaultValues,
serverless.ServingIngressDomain,
).
WithResources(serverless.ServingCertificateResource).
servingGateway := feature.Define("serverless-serving-gateways").
ManifestsLocation(Resources.Location).
Manifests(
path.Join(Resources.GatewaysDir),
).
Load()
if serverlessGwErr != nil {
return serverlessGwErr
}

return nil
}
}
WithData(
serverless.FeatureData.IngressDomain.Define(&k.Serving).AsAction(),
serverless.FeatureData.CertificateName.Define(&k.Serving).AsAction(),
serverless.FeatureData.Serving.Define(&k.Serving).AsAction(),
servicemesh.FeatureData.ControlPlane.Define(dsciSpec).AsAction(),
).
WithResources(serverless.ServingCertificateResource).
PreConditions(serverless.EnsureServerlessServingDeployed)

func PopulateComponentSettings(k *Kserve) feature.Action {
return func(_ context.Context, f *feature.Feature) error {
f.Spec.Serving = &k.Serving
return nil
return registry.Add(
servingDeployment,
istioSecretFiltering,
servingGateway,
)
}
}
34 changes: 16 additions & 18 deletions components/kserve/servicemesh_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
func (k *Kserve) configureServiceMesh(ctx context.Context, cli client.Client, dscispec *dsciv1.DSCInitializationSpec) error {
if dscispec.ServiceMesh != nil {
if dscispec.ServiceMesh.ManagementState == operatorv1.Managed && k.GetManagementState() == operatorv1.Managed {
serviceMeshInitializer := feature.ComponentFeaturesHandler(k.GetComponentName(), dscispec, k.defineServiceMeshFeatures(ctx, cli))
serviceMeshInitializer := feature.ComponentFeaturesHandler(k.GetComponentName(), dscispec.ApplicationsNamespace, k.defineServiceMeshFeatures(ctx, cli, dscispec))
return serviceMeshInitializer.Apply(ctx)
}
if dscispec.ServiceMesh.ManagementState == operatorv1.Unmanaged && k.GetManagementState() == operatorv1.Managed {
Expand All @@ -29,29 +29,34 @@ func (k *Kserve) configureServiceMesh(ctx context.Context, cli client.Client, ds
}

func (k *Kserve) removeServiceMeshConfigurations(ctx context.Context, cli client.Client, dscispec *dsciv1.DSCInitializationSpec) error {
serviceMeshInitializer := feature.ComponentFeaturesHandler(k.GetComponentName(), dscispec, k.defineServiceMeshFeatures(ctx, cli))
serviceMeshInitializer := feature.ComponentFeaturesHandler(k.GetComponentName(), dscispec.ApplicationsNamespace, k.defineServiceMeshFeatures(ctx, cli, dscispec))
return serviceMeshInitializer.Delete(ctx)
}

func (k *Kserve) defineServiceMeshFeatures(ctx context.Context, cli client.Client) feature.FeaturesProvider {
return func(handler *feature.FeaturesHandler) error {
func (k *Kserve) defineServiceMeshFeatures(ctx context.Context, cli client.Client, dscispec *dsciv1.DSCInitializationSpec) feature.FeaturesProvider {
return func(registry feature.FeaturesRegistry) error {
authorinoInstalled, err := cluster.SubscriptionExists(ctx, cli, "authorino-operator")
if err != nil {
return fmt.Errorf("failed to list subscriptions %w", err)
}

if authorinoInstalled {
kserveExtAuthzErr := feature.CreateFeature("kserve-external-authz").
For(handler).
kserveExtAuthzErr := registry.Add(feature.Define("kserve-external-authz").
ManifestsLocation(Resources.Location).
Manifests(
path.Join(Resources.ServiceMeshDir, "activator-envoyfilter.tmpl.yaml"),
path.Join(Resources.ServiceMeshDir, "envoy-oauth-temp-fix.tmpl.yaml"),
path.Join(Resources.ServiceMeshDir, "kserve-predictor-authorizationpolicy.tmpl.yaml"),
path.Join(Resources.ServiceMeshDir, "z-migrations"),
).
WithData(servicemesh.ClusterDetails).
Load()
WithData(
feature.Entry("Domain", cluster.GetDomain),
servicemesh.FeatureData.ControlPlane.Define(dscispec).AsAction(),
).
WithData(
servicemesh.FeatureData.Authorization.All(dscispec)...,
),
)

if kserveExtAuthzErr != nil {
return kserveExtAuthzErr
Expand All @@ -60,19 +65,12 @@ func (k *Kserve) defineServiceMeshFeatures(ctx context.Context, cli client.Clien
fmt.Println("WARN: Authorino operator is not installed on the cluster, skipping authorization capability")
}

temporaryFixesErr := feature.CreateFeature("kserve-temporary-fixes").
For(handler).
return registry.Add(feature.Define("kserve-temporary-fixes").
ManifestsLocation(Resources.Location).
Manifests(
path.Join(Resources.ServiceMeshDir, "grpc-envoyfilter-temp-fix.tmpl.yaml"),
).
WithData(servicemesh.ClusterDetails).
Load()

if temporaryFixesErr != nil {
return temporaryFixesErr
}

return nil
WithData(servicemesh.FeatureData.ControlPlane.Define(dscispec).AsAction()),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: maistra.io/v1
kind: ServiceMeshMember
metadata:
name: default
namespace: {{ .Auth.Namespace }}
namespace: {{ .AuthNamespace }}
spec:
controlPlaneRef:
namespace: {{ .ControlPlane.Namespace }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: operator.authorino.kuadrant.io/v1beta1
kind: Authorino
metadata:
name: {{ .AuthProviderName }}
namespace: {{ .Auth.Namespace }}
namespace: {{ .AuthNamespace }}
spec:
authConfigLabelSelectors: security.opendatahub.io/authorization-group=default
clusterWide: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .AuthProviderName }}
namespace: {{ .Auth.Namespace }}
namespace: {{ .AuthNamespace }}
spec:
template:
metadata:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ spec:
techPreview:
meshConfig:
extensionProviders:
- name: {{ .AppNamespace }}-auth-provider
- name: {{ .AuthExtensionName }}
envoyExtAuthzGrpc:
service: {{ .AuthProviderName }}-authorino-authorization.{{ .Auth.Namespace }}.svc.cluster.local
service: {{ .AuthProviderName }}-authorino-authorization.{{ .AuthNamespace }}.svc.cluster.local
port: 50051
Loading

0 comments on commit 8d2da19

Please sign in to comment.