Skip to content

Commit

Permalink
[cherry-pick]: odh opendatahub-io#809
Browse files Browse the repository at this point in the history
Signed-off-by: Wen Zhou <wenzhou@redhat.com>
  • Loading branch information
zdtsw committed Jan 18, 2024
1 parent 9c64fb3 commit 4e63365
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 132 deletions.
12 changes: 0 additions & 12 deletions controllers/dscinitialization/servicemesh_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,6 @@ func configureServiceMeshFeatures(s *feature.FeaturesInitializer) error {
}
s.Features = append(s.Features, smcpCreation)

noDefaultNetworkPolicies, errNp := feature.CreateFeature("mesh-control-plane-no-default-network-policies").
For(s.DSCInitializationSpec).
Manifests(
path.Join(rootDir, templatesDir, "base", "control-plane-disable-networkpolicies.patch.tmpl"),
).
Load()

if errNp != nil {
return errNp
}
s.Features = append(s.Features, noDefaultNetworkPolicies)

if serviceMeshSpec.ControlPlane.MetricsCollection == "Istio" {
metricsCollection, errMetrics := feature.CreateFeature("mesh-metrics-collection").
For(s.DSCInitializationSpec).
Expand Down

This file was deleted.

112 changes: 0 additions & 112 deletions tests/integration/features/servicemesh_feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ package features_test

import (
"context"
"io"
"os"
"path"
"path/filepath"

apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -16,7 +12,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/envtest"

dscv1 "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/servicemesh"
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/gvr"
Expand Down Expand Up @@ -100,60 +95,6 @@ var _ = Describe("Service Mesh feature", func() {
})
})
})

Describe("control plane configuration", func() {

var (
dsciSpec *dscv1.DSCInitializationSpec
smcpCRD *apiextensionsv1.CustomResourceDefinition
name = "data-science-smcp"
appNamespace = "opendatahub"
)

BeforeEach(func() {
dsciSpec = newDSCInitializationSpec(appNamespace)
smcpCRD = installServiceMeshControlPlaneCRD()
})

AfterEach(func() {
defer objectCleaner.DeleteAll(smcpCRD)
})

It("should disable automated network policy by patching existing SMCP", func() {
// given
namespace := envtestutil.AppendRandomNameTo(testNamespacePrefix)
ns := createNamespace(namespace)
Expect(envTestClient.Create(context.Background(), ns)).To(Succeed())
defer objectCleaner.DeleteAll(ns)

createServiceMeshControlPlane(name, namespace)

dsciSpec.ServiceMesh.ControlPlane.Name = name
dsciSpec.ServiceMesh.ControlPlane.Namespace = namespace

controlPlaneWithNetworkPoliciesMgmtDisabled, err := feature.CreateFeature("control-plane-with-disabled-network-policies").
For(dsciSpec).
Manifests(fromTestTmpDir(path.Join("templates/servicemesh/base", "control-plane-disable-networkpolicies.patch.tmpl"))).
UsingConfig(envTest.Config).
Load()

Expect(err).ToNot(HaveOccurred())

// when
Expect(controlPlaneWithNetworkPoliciesMgmtDisabled.Apply()).To(Succeed())

// then
serviceMeshControlPlane, err := getServiceMeshControlPlane(envTest.Config, namespace, name)
Expect(err).ToNot(HaveOccurred())

networkPolicyManagement, found, err := unstructured.NestedBool(serviceMeshControlPlane.Object, "spec", "security", "manageNetworkPolicy")
Expect(err).ToNot(HaveOccurred())
Expect(found).To(BeTrue())
Expect(networkPolicyManagement).To(BeFalse())
})

})

})

func installServiceMeshControlPlaneCRD() *apiextensionsv1.CustomResourceDefinition {
Expand Down Expand Up @@ -273,56 +214,3 @@ func createSMCPInCluster(cfg *rest.Config, smcpObj *unstructured.Unstructured, n

return nil
}

func getServiceMeshControlPlane(cfg *rest.Config, namespace, name string) (*unstructured.Unstructured, error) {
dynamicClient, err := dynamic.NewForConfig(cfg)
if err != nil {
return nil, err
}

smcp, err := dynamicClient.Resource(gvr.SMCP).Namespace(namespace).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return nil, err
}

return smcp, nil
}

func fromTestTmpDir(fileName string) string {
root, err := envtestutil.FindProjectRoot()
Expect(err).ToNot(HaveOccurred())

tmpDir := filepath.Join(os.TempDir(), envtestutil.RandomUUIDName(16))
if err := os.Mkdir(tmpDir, os.ModePerm); err != nil {
Fail(err.Error())
}

src := path.Join(root, "pkg", "feature", fileName)
dest := path.Join(tmpDir, fileName)
if err := copyFile(src, dest); err != nil {
Fail(err.Error())
}

return dest
}

func copyFile(src, dst string) error {
source, err := os.Open(src)
if err != nil {
return err
}
defer source.Close()

if err := os.MkdirAll(filepath.Dir(dst), os.ModePerm); err != nil {
return err
}

destination, err := os.Create(dst)
if err != nil {
return err
}
defer destination.Close()

_, err = io.Copy(destination, source)
return err
}

0 comments on commit 4e63365

Please sign in to comment.