-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
159 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { describe, expect, it } from "@jest/globals"; | ||
import { UDSConfig } from "../../../config"; | ||
import { generateServiceEntry } from "./service-entry"; | ||
import { Expose, Gateway, IstioLocation, IstioResolution } from "../../crd"; | ||
|
||
describe("test generate service entry", () => { | ||
const ownerRefs = [ | ||
{ | ||
apiVersion: "uds.dev/v1alpha1", | ||
kind: "Package", | ||
name: "test", | ||
uid: "f50120aa-2713-4502-9496-566b102b1174", | ||
}, | ||
]; | ||
|
||
const host = "test"; | ||
const port = 8080; | ||
const service = "test-service" | ||
|
||
const namespace = "test"; | ||
const pkgName = "test"; | ||
const generation = "1"; | ||
|
||
it("should create a simple ServiceEntry object", () => { | ||
const expose: Expose = { | ||
host, | ||
port, | ||
service, | ||
}; | ||
|
||
const payload = generateServiceEntry(expose, namespace, pkgName, generation, ownerRefs); | ||
|
||
expect(payload).toBeDefined(); | ||
expect(payload.metadata?.name).toEqual(`${pkgName}-${Gateway.Tenant}-${host}`); | ||
expect(payload.metadata?.namespace).toEqual(namespace); | ||
|
||
expect(payload.spec?.hosts).toBeDefined(); | ||
expect(payload.spec!.hosts![0]).toEqual(`${host}.${UDSConfig.domain}`); | ||
|
||
expect(payload.spec!.location).toEqual(IstioLocation.MeshInternal); | ||
expect(payload.spec!.resolution).toEqual(IstioResolution.DNS); | ||
|
||
expect(payload.spec?.ports).toBeDefined(); | ||
expect(payload.spec!.ports![0].name).toEqual("https"); | ||
expect(payload.spec!.ports![0].number).toEqual(443); | ||
expect(payload.spec!.ports![0].protocol).toEqual("HTTPS"); | ||
|
||
expect(payload.spec?.endpoints).toBeDefined(); | ||
expect(payload.spec!.endpoints![0].address).toEqual(`${Gateway.Tenant}-ingressgateway.istio-${Gateway.Tenant}-gateway.svc.cluster.local`); | ||
}); | ||
}); |
104 changes: 104 additions & 0 deletions
104
src/pepr/operator/controllers/istio/virtual-service.spec.ts
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,104 @@ | ||
import { describe, expect, it } from "@jest/globals"; | ||
import { UDSConfig } from "../../../config"; | ||
import { generateVirtualService } from "./virtual-service"; | ||
import { Expose, Gateway } from "../../crd"; | ||
|
||
describe("test generate virtual service", () => { | ||
const ownerRefs = [ | ||
{ | ||
apiVersion: "uds.dev/v1alpha1", | ||
kind: "Package", | ||
name: "test", | ||
uid: "f50120aa-2713-4502-9496-566b102b1174", | ||
}, | ||
]; | ||
|
||
const host = "test"; | ||
const port = 8080; | ||
const service = "test-service" | ||
|
||
const namespace = "test"; | ||
const pkgName = "test"; | ||
const generation = "1"; | ||
|
||
it("should create a simple VirtualService object", () => { | ||
const expose: Expose = { | ||
host, | ||
port, | ||
service, | ||
}; | ||
|
||
const payload = generateVirtualService(expose, namespace, pkgName, generation, ownerRefs); | ||
|
||
expect(payload).toBeDefined(); | ||
expect(payload.metadata?.name).toEqual(`${pkgName}-${Gateway.Tenant}-${host}-${port}-${service}`); | ||
expect(payload.metadata?.namespace).toEqual(namespace); | ||
|
||
expect(payload.spec?.hosts).toBeDefined(); | ||
expect(payload.spec!.hosts![0]).toEqual(`${host}.${UDSConfig.domain}`); | ||
|
||
expect(payload.spec?.http).toBeDefined(); | ||
expect(payload.spec!.http![0].route).toBeDefined(); | ||
expect(payload.spec!.http![0].route![0].destination?.host).toEqual(`${service}.${namespace}.svc.cluster.local`); | ||
expect(payload.spec!.http![0].route![0].destination?.port?.number).toEqual(port); | ||
|
||
expect(payload.spec?.gateways).toBeDefined(); | ||
expect(payload.spec!.gateways![0]).toEqual(`istio-${Gateway.Tenant}-gateway/${Gateway.Tenant}-gateway`); | ||
}); | ||
|
||
it("should create an admin VirtualService object", () => { | ||
const gateway = Gateway.Admin; | ||
const expose: Expose = { | ||
gateway, | ||
host, | ||
port, | ||
service, | ||
}; | ||
|
||
const payload = generateVirtualService(expose, namespace, pkgName, generation, ownerRefs); | ||
|
||
expect(payload).toBeDefined(); | ||
expect(payload.spec?.hosts).toBeDefined(); | ||
expect(payload.spec!.hosts![0]).toEqual(`${host}.admin.${UDSConfig.domain}`); | ||
}); | ||
|
||
it("should create an advancedHttp VirtualService object", () => { | ||
const advancedHTTP = { | ||
directResponse: { status: 404 } | ||
} | ||
const expose: Expose = { | ||
host, | ||
port, | ||
service, | ||
advancedHTTP, | ||
}; | ||
|
||
const payload = generateVirtualService(expose, namespace, pkgName, generation, ownerRefs); | ||
|
||
expect(payload).toBeDefined(); | ||
expect(payload.spec?.http).toBeDefined(); | ||
expect(payload.spec!.http![0].route).not.toBeDefined(); | ||
expect(payload.spec!.http![0].directResponse?.status).toEqual(404); | ||
}); | ||
|
||
it("should create a passthrough VirtualService object", () => { | ||
const gateway = Gateway.Passthrough; | ||
const expose: Expose = { | ||
gateway, | ||
host, | ||
port, | ||
service, | ||
}; | ||
|
||
const payload = generateVirtualService(expose, namespace, pkgName, generation, ownerRefs); | ||
|
||
expect(payload).toBeDefined(); | ||
expect(payload.spec?.tls).toBeDefined(); | ||
expect(payload.spec!.tls![0].match).toBeDefined(); | ||
expect(payload.spec!.tls![0].match![0].port).toEqual(443); | ||
expect(payload.spec!.tls![0].match![0].sniHosts![0]).toEqual(`${host}.${UDSConfig.domain}`); | ||
expect(payload.spec!.tls![0].route).toBeDefined(); | ||
expect(payload.spec!.http![0].route![0].destination?.host).toEqual(`${service}.${namespace}.svc.cluster.local`); | ||
expect(payload.spec!.http![0].route![0].destination?.port?.number).toEqual(port); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -2,6 +2,7 @@ export { | |
Allow, | ||
Direction, | ||
Expose, | ||
Monitor, | ||
Gateway, | ||
Phase, | ||
Status as PkgStatus, | ||
|