forked from opendatahub-io/opendatahub-operator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: parameterizes gateway namespace for kubeflow
Update components/workbenches/workbenches.go Co-authored-by: Bartosz Majsak <[email protected]> consolidate regex and string replace funcs into one w helper move to package, add testing move out gateway const rename to ossmcommon clean up unit tests rename pkg, move io funcs, rename gw func
- Loading branch information
1 parent
78a62f2
commit 724837d
Showing
8 changed files
with
117 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package servicemesh | ||
|
||
import ( | ||
"fmt" | ||
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/common" | ||
"path/filepath" | ||
) | ||
|
||
const ( | ||
gatewayPattern = `ISTIO_GATEWAY=(.*)` | ||
) | ||
|
||
// OverwriteIstioGatewayVar replaces the ISTIO_GATEWAY with given namespace and "odh-gateway" in the specified ossm.env file. | ||
// This is used in conjunction with kustomize overlays for Kubeflow notebook controllers. By overwritting referenced we can set | ||
// proper values for environment variables populated through Kustomize. | ||
func OverwriteIstioGatewayVar(namespace, path string) error { | ||
envFile := filepath.Join(path, "ossm.env") | ||
replacement := fmt.Sprintf("ISTIO_GATEWAY=%s", namespace+"/odh-gateway") | ||
|
||
return common.ReplaceInFile(envFile, map[string]string{gatewayPattern: replacement}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package servicemesh_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/opendatahub-io/opendatahub-operator/v2/pkg/feature/servicemesh" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
var _ = Describe("Overwriting gateway name in env file", func() { | ||
|
||
It("should replace gateway name in the file", func() { | ||
namespace := "test-namespace" | ||
path := createTempEnvFile() | ||
Expect(servicemesh.OverwriteIstioGatewayVar(namespace, path)).To(Succeed()) | ||
|
||
updatedContents, err := os.ReadFile(filepath.Join(path, "ossm.env")) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
Expect(string(updatedContents)).To(ContainSubstring("ISTIO_GATEWAY=test-namespace/odh-gateway")) | ||
}) | ||
|
||
It("should fail if the file does not exist", func() { | ||
Expect(servicemesh.OverwriteIstioGatewayVar("test-namespace", "wrong_directory")).To(Not(Succeed())) | ||
}) | ||
|
||
It("should not modify other text in the file", func() { | ||
namespace := "test-namespace" | ||
path := createTempEnvFile() | ||
|
||
Expect(servicemesh.OverwriteIstioGatewayVar(namespace, path)).To(Succeed()) | ||
|
||
updatedContents, err := os.ReadFile(filepath.Join(path, "ossm.env")) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
Expect(string(updatedContents)).To(ContainSubstring("AnotherSetting=value")) | ||
}) | ||
}) | ||
|
||
const testContent = ` | ||
ISTIO_GATEWAY=default-namespace/odh-gateway | ||
AnotherSetting=value` | ||
|
||
func createTempEnvFile() string { | ||
var err error | ||
|
||
tempDir := GinkgoT().TempDir() | ||
|
||
tempFilePath := filepath.Join(tempDir, "ossm.env") | ||
tempFile, err := os.Create(tempFilePath) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
_, err = tempFile.WriteString(testContent) | ||
Expect(err).NotTo(HaveOccurred()) | ||
defer tempFile.Close() | ||
|
||
return tempDir | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package servicemesh_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestServiceMeshSetup(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Service Mesh setup unit tests") | ||
} |