Skip to content

Commit

Permalink
[cherry-pick]: from incubation to 2.9 for grpc EnvoyFilter (red-hat-d…
Browse files Browse the repository at this point in the history
…ata-services#219)

* chore(api): move infrastructure/v1 to apis folder (opendatahub-io#894)

Collects all APIs under the same parent package structure.

* fix: Rework operator precondition checks (opendatahub-io#899)

* init commit

* tmp: switch to subsciption

* tmp

* fix up testing

* linter on import

* minor self nits

* add bracket, make

* use found,err for checking subscription

Co-authored-by: Bartosz Majsak <[email protected]>

* fix import + test error expected outputs

* directly return errs rather than log and ret

Co-authored-by: Bartosz Majsak <[email protected]>

* remove unused log var from condiitons

* move const fixtures to separate package

* move creating op subscription to function

* rename noop features in testing

* remove redundant comments

Co-authored-by: Bartosz Majsak <[email protected]>

* move CreateSubscription to fixtures

---------

Co-authored-by: Bartosz Majsak <[email protected]>

* chore(feature): passes component name instead of whole struct (opendatahub-io#903)

Co-authored-by: Aslak Knutsen <[email protected]>

Simplify API as there is no need to pass the entire Component struct.

* kserve: add grpconly envoy filter (opendatahub-io#888)

---------

Co-authored-by: Aslak Knutsen <[email protected]>
Co-authored-by: Cameron Garrison <[email protected]>
Co-authored-by: Bartosz Majsak <[email protected]>
Co-authored-by: Daniele <[email protected]>
  • Loading branch information
5 people authored Mar 15, 2024
1 parent 822ad1f commit 5b7153b
Show file tree
Hide file tree
Showing 19 changed files with 159 additions and 217 deletions.
1 change: 0 additions & 1 deletion Dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ COPY components/ components/
COPY controllers/ controllers/
COPY main.go main.go
COPY pkg/ pkg/
COPY infrastructure/ infrastructure/

# Copy monitoring config
COPY config/monitoring/ /opt/odh-manifests/monitoring/
Expand Down
2 changes: 1 addition & 1 deletion apis/dscinitialization/v1/dscinitialization_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/infrastructure/v1"
infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/v1"
)

// +operator-sdk:csv:customresourcedefinitions:order=1
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion components/kserve/kserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/components"
infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/infrastructure/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/monitoring"
Expand Down
4 changes: 2 additions & 2 deletions components/kserve/kserve_config_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (k *Kserve) configureServerless(cli client.Client, instance *dsciv1.DSCInit
return dependOpsErrors
}

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

if err := serverlessFeatures.Apply(); err != nil {
return err
Expand All @@ -148,7 +148,7 @@ func (k *Kserve) configureServerless(cli client.Client, instance *dsciv1.DSCInit
}

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

return serverlessFeatures.Delete()
}
Expand Down
16 changes: 14 additions & 2 deletions components/kserve/servicemesh_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func (k *Kserve) configureServiceMesh(dscispec *dsciv1.DSCInitializationSpec) error {
if dscispec.ServiceMesh.ManagementState == operatorv1.Managed && k.GetManagementState() == operatorv1.Managed {
serviceMeshInitializer := feature.ComponentFeaturesHandler(k, dscispec, k.defineServiceMeshFeatures())
serviceMeshInitializer := feature.ComponentFeaturesHandler(k.GetComponentName(), dscispec, k.defineServiceMeshFeatures())
return serviceMeshInitializer.Apply()
}
if dscispec.ServiceMesh.ManagementState == operatorv1.Unmanaged && k.GetManagementState() == operatorv1.Managed {
Expand All @@ -23,7 +23,7 @@ func (k *Kserve) configureServiceMesh(dscispec *dsciv1.DSCInitializationSpec) er
}

func (k *Kserve) removeServiceMeshConfigurations(dscispec *dsciv1.DSCInitializationSpec) error {
serviceMeshInitializer := feature.ComponentFeaturesHandler(k, dscispec, k.defineServiceMeshFeatures())
serviceMeshInitializer := feature.ComponentFeaturesHandler(k.GetComponentName(), dscispec, k.defineServiceMeshFeatures())
return serviceMeshInitializer.Delete()
}

Expand All @@ -44,6 +44,18 @@ func (k *Kserve) defineServiceMeshFeatures() feature.FeaturesProvider {
return kserveExtAuthzErr
}

temporaryFixesErr := feature.CreateFeature("kserve-temporary-fixes").
For(handler).
Manifests(
path.Join(feature.KServeDir, "grpc-envoyfilter-temp-fix.tmpl"),
).
WithData(servicemesh.ClusterDetails).
Load()

if temporaryFixesErr != nil {
return temporaryFixesErr
}

return nil
}
}
2 changes: 1 addition & 1 deletion pkg/feature/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/config"

featurev1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/features/v1"
infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/infrastructure/v1"
infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/v1"
)

type partialBuilder func(f *Feature) error
Expand Down
2 changes: 1 addition & 1 deletion pkg/feature/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/infrastructure/v1"
infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/v1"
)

func (f *Feature) CreateSelfSignedCertificate(secretName string, certificateType infrav1.CertType, domain, namespace string) error {
Expand Down
5 changes: 2 additions & 3 deletions pkg/feature/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

v1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
featurev1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/features/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/components"
)

// FeaturesHandler coordinates feature creations and removal from within controllers.
Expand All @@ -30,10 +29,10 @@ func ClusterFeaturesHandler(dsci *v1.DSCInitialization, def FeaturesProvider) *F
}
}

func ComponentFeaturesHandler(component components.ComponentInterface, spec *v1.DSCInitializationSpec, def FeaturesProvider) *FeaturesHandler {
func ComponentFeaturesHandler(componentName string, spec *v1.DSCInitializationSpec, def FeaturesProvider) *FeaturesHandler {
return &FeaturesHandler{
DSCInitializationSpec: spec,
source: featurev1.Source{Type: featurev1.ComponentType, Name: component.GetComponentName()},
source: featurev1.Source{Type: featurev1.ComponentType, Name: componentName},
featuresProvider: def,
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Temporary workaround for https://issues.redhat.com/browse/RHOAIENG-165
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: grpc-only
namespace: {{ .ControlPlane.Namespace }}
labels:
app.opendatahub.io/kserve: "true"
app.kubernetes.io/part-of: kserve
opendatahub.io/related-to: RHOAIENG-165
spec:
priority: 20
workloadSelector:
labels:
protocol: "grpconly"
configPatches:
- applyTo: HTTP_FILTER
match:
context: SIDECAR_INBOUND
listener:
filterChain:
filter:
name: envoy.filters.network.http_connection_manager
patch:
operation: INSERT_BEFORE
value:
name: envoy.filters.http.lua
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua
inlineCode: |
function envoy_on_request(request_handle)
local header_value = request_handle:headers():get("Content-Type")
local pattern = "^application/grpc"
if header_value:find(pattern) == nil then
request_handle:respond({[":status"] = "400"}, "Invalid request, this endpoint only serves grpc.")
end
end
2 changes: 1 addition & 1 deletion pkg/feature/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"strings"

featurev1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/features/v1"
infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/infrastructure/v1"
infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/v1"
)

type Spec struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
kfdefv1 "github.com/opendatahub-io/opendatahub-operator/apis/kfdef.apps.kubeflow.org/v1"
dsc "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
dsci "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/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 All @@ -38,7 +39,6 @@ import (
"github.com/opendatahub-io/opendatahub-operator/v2/components/modelmeshserving"
"github.com/opendatahub-io/opendatahub-operator/v2/components/ray"
"github.com/opendatahub-io/opendatahub-operator/v2/components/workbenches"
infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/infrastructure/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/cluster"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/deploy"
)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

dsc "github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1"
dsci "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/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 All @@ -25,7 +26,6 @@ import (
"github.com/opendatahub-io/opendatahub-operator/v2/components/ray"
"github.com/opendatahub-io/opendatahub-operator/v2/components/trustyai"
"github.com/opendatahub-io/opendatahub-operator/v2/components/workbenches"
infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/infrastructure/v1"
)

func (tc *testContext) waitForControllerDeployment(name string, replicas int32) error {
Expand Down
14 changes: 7 additions & 7 deletions tests/integration/features/serverless_feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/envtest"

dsciv1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1"
infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/v1"
"github.com/opendatahub-io/opendatahub-operator/v2/components/kserve"
infrav1 "github.com/opendatahub-io/opendatahub-operator/v2/infrastructure/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/tests/envtestutil"
Expand Down Expand Up @@ -48,7 +48,7 @@ var _ = Describe("Serverless feature", func() {

It("should fail on precondition check", func() {
// given
featuresHandler := feature.ComponentFeaturesHandler(kserveComponent, &dsci.Spec, func(handler *feature.FeaturesHandler) error {
featuresHandler := feature.ComponentFeaturesHandler(kserveComponent.GetComponentName(), &dsci.Spec, func(handler *feature.FeaturesHandler) error {
verificationFeatureErr := feature.CreateFeature("no-serverless-operator-check").
For(handler).
UsingConfig(envTest.Config).
Expand Down Expand Up @@ -95,7 +95,7 @@ var _ = Describe("Serverless feature", func() {

It("should succeed checking operator installation using precondition", func() {
// when
featuresHandler := feature.ComponentFeaturesHandler(kserveComponent, &dsci.Spec, func(handler *feature.FeaturesHandler) error {
featuresHandler := feature.ComponentFeaturesHandler(kserveComponent.GetComponentName(), &dsci.Spec, func(handler *feature.FeaturesHandler) error {
verificationFeatureErr := feature.CreateFeature("serverless-operator-check").
For(handler).
UsingConfig(envTest.Config).
Expand All @@ -113,7 +113,7 @@ var _ = Describe("Serverless feature", func() {

It("should succeed if serving is not installed for KNative serving precondition", func() {
// when
featuresHandler := feature.ComponentFeaturesHandler(kserveComponent, &dsci.Spec, func(handler *feature.FeaturesHandler) error {
featuresHandler := feature.ComponentFeaturesHandler(kserveComponent.GetComponentName(), &dsci.Spec, func(handler *feature.FeaturesHandler) error {
verificationFeatureErr := feature.CreateFeature("no-serving-installed-yet").
For(handler).
UsingConfig(envTest.Config).
Expand Down Expand Up @@ -142,7 +142,7 @@ var _ = Describe("Serverless feature", func() {
Expect(envTestClient.Create(context.TODO(), knativeServing)).To(Succeed())

// when
featuresHandler := feature.ComponentFeaturesHandler(kserveComponent, &dsci.Spec, func(handler *feature.FeaturesHandler) error {
featuresHandler := feature.ComponentFeaturesHandler(kserveComponent.GetComponentName(), &dsci.Spec, func(handler *feature.FeaturesHandler) error {
verificationFeatureErr := feature.CreateFeature("serving-already-installed").
For(handler).
UsingConfig(envTest.Config).
Expand Down Expand Up @@ -239,7 +239,7 @@ var _ = Describe("Serverless feature", func() {
kserveComponent.Serving.IngressGateway.Certificate.Type = infrav1.SelfSigned
kserveComponent.Serving.IngressGateway.Domain = fixtures.TestDomainFooCom

featuresHandler := feature.ComponentFeaturesHandler(kserveComponent, &dsci.Spec, func(handler *feature.FeaturesHandler) error {
featuresHandler := feature.ComponentFeaturesHandler(kserveComponent.GetComponentName(), &dsci.Spec, func(handler *feature.FeaturesHandler) error {
verificationFeatureErr := feature.CreateFeature("tls-secret-creation").
For(handler).
UsingConfig(envTest.Config).
Expand Down Expand Up @@ -278,7 +278,7 @@ var _ = Describe("Serverless feature", func() {
// given
kserveComponent.Serving.IngressGateway.Certificate.Type = infrav1.Provided
kserveComponent.Serving.IngressGateway.Domain = fixtures.TestDomainFooCom
featuresHandler := feature.ComponentFeaturesHandler(kserveComponent, &dsci.Spec, func(handler *feature.FeaturesHandler) error {
featuresHandler := feature.ComponentFeaturesHandler(kserveComponent.GetComponentName(), &dsci.Spec, func(handler *feature.FeaturesHandler) error {
verificationFeatureErr := feature.CreateFeature("tls-secret-creation").
For(handler).
UsingConfig(envTest.Config).
Expand Down
Loading

0 comments on commit 5b7153b

Please sign in to comment.