Repository: cdk8s-team/cdk8s-plus (ts)

Issue:
Add support for configuring scheme in http probes
Here is the k8s documentation https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/#http-probes

Pull request:
feat(probe): ability to configure `scheme`
Signed-off-by: rakshith <rakshith@yahooinc.com>

Fixes #985 

Patch:
diff --git a/src/_action.ts b/src/_action.ts
index 8c806010..c9082229 100644
--- a/src/_action.ts
+++ b/src/_action.ts
@@ -1,5 +1,6 @@
 import { Container } from './container';
 import * as k8s from './imports/k8s';
+import { ConnectionScheme } from './probe';
 
 /**
  * Utility class to implement the conversion between our API and the k8s action
@@ -20,10 +21,11 @@ export class Action {
     return { command };
   }
 
-  public static fromHttpGet(container: Container, path: string, options: { port?: number } = { }): k8s.HttpGetAction {
+  public static fromHttpGet(container: Container, path: string, options: { port?: number; scheme?: ConnectionScheme } = { }): k8s.HttpGetAction {
     return {
       path,
       port: k8s.IntOrString.fromNumber(options.port ?? container.port ?? 80),
+      scheme: options.scheme ?? ConnectionScheme.HTTP,
     };
   }
 }
\ No newline at end of file
diff --git a/src/probe.ts b/src/probe.ts
index 9b1c71b3..e10fc8e8 100644
--- a/src/probe.ts
+++ b/src/probe.ts
@@ -56,6 +56,18 @@ export interface ProbeOptions {
   readonly timeoutSeconds?: Duration;
 }
 
+export enum ConnectionScheme {
+  /**
+   * Use HTTP request for connecting to host.
+   */
+  HTTP = 'HTTP',
+
+  /**
+   * Use HTTPS request for connecting to host.
+   */
+  HTTPS = 'HTTPS'
+}
+
 /**
  * Options for `Probe.fromHttpGet()`.
  */
@@ -66,6 +78,13 @@ export interface HttpGetProbeOptions extends ProbeOptions {
    * @default - defaults to `container.port`.
    */
   readonly port?: number;
+
+  /**
+   *  Scheme to use for connecting to the host (HTTP or HTTPS).
+   *
+   *  @default ConnectionScheme.HTTP
+   */
+  readonly scheme?: ConnectionScheme;
 }
 
 /**


Test patch:
diff --git a/test/container.test.ts b/test/container.test.ts
index b29aaf28..577d0acc 100644
--- a/test/container.test.ts
+++ b/test/container.test.ts
@@ -1,7 +1,7 @@
 import * as cdk8s from 'cdk8s';
 import { Size, Testing } from 'cdk8s';
 import * as kplus from '../src';
-import { Container, Cpu, Handler } from '../src';
+import { Container, Cpu, Handler, ConnectionScheme } from '../src';
 import * as k8s from '../src/imports/k8s';
 
 describe('EnvValue', () => {
@@ -346,19 +346,21 @@ describe('Container', () => {
       image: 'foo',
       readiness: kplus.Probe.fromHttpGet('/ping', {
         timeoutSeconds: cdk8s.Duration.minutes(2),
+        scheme: ConnectionScheme.HTTPS,
       }),
       liveness: kplus.Probe.fromHttpGet('/live', {
         timeoutSeconds: cdk8s.Duration.minutes(3),
       }),
       startup: kplus.Probe.fromHttpGet('/startup', {
         timeoutSeconds: cdk8s.Duration.minutes(4),
+        scheme: ConnectionScheme.HTTP,
       }),
     });
 
     // THEN
     expect(container._toKube().readinessProbe).toEqual({
       failureThreshold: 3,
-      httpGet: { path: '/ping', port: k8s.IntOrString.fromNumber(80) },
+      httpGet: { path: '/ping', port: k8s.IntOrString.fromNumber(80), scheme: 'HTTPS' },
       initialDelaySeconds: undefined,
       periodSeconds: undefined,
       successThreshold: undefined,
@@ -366,7 +368,7 @@ describe('Container', () => {
     });
     expect(container._toKube().livenessProbe).toEqual({
       failureThreshold: 3,
-      httpGet: { path: '/live', port: k8s.IntOrString.fromNumber(80) },
+      httpGet: { path: '/live', port: k8s.IntOrString.fromNumber(80), scheme: 'HTTP' },
       initialDelaySeconds: undefined,
       periodSeconds: undefined,
       successThreshold: undefined,
@@ -374,7 +376,7 @@ describe('Container', () => {
     });
     expect(container._toKube().startupProbe).toEqual({
       failureThreshold: 3,
-      httpGet: { path: '/startup', port: k8s.IntOrString.fromNumber(80) },
+      httpGet: { path: '/startup', port: k8s.IntOrString.fromNumber(80), scheme: 'HTTP' },
       initialDelaySeconds: undefined,
       periodSeconds: undefined,
       successThreshold: undefined,
diff --git a/test/handler.test.ts b/test/handler.test.ts
index 39fa8651..9fdb40de 100644
--- a/test/handler.test.ts
+++ b/test/handler.test.ts
@@ -10,7 +10,7 @@ test('fromCommand', () => {
 test('fromHttpGet', () => {
   const container = new Container({ image: 'image' });
   const handler = Handler.fromHttpGet('/path');
-  expect(handler._toKube(container).httpGet).toEqual({ path: '/path', port: IntOrString.fromNumber(80) });
+  expect(handler._toKube(container).httpGet).toEqual({ path: '/path', port: IntOrString.fromNumber(80), scheme: 'HTTP' });
 });
 
 test('fromTcpSocket', () => {
diff --git a/test/probe.test.ts b/test/probe.test.ts
index 0d96cb47..85fed756 100644
--- a/test/probe.test.ts
+++ b/test/probe.test.ts
@@ -16,6 +16,7 @@ describe('fromHttpGet()', () => {
       httpGet: {
         path: '/hello',
         port: IntOrString.fromNumber(5555),
+        scheme: 'HTTP',
       },
       initialDelaySeconds: undefined,
       periodSeconds: undefined,
@@ -37,6 +38,7 @@ describe('fromHttpGet()', () => {
       httpGet: {
         path: '/hello',
         port: IntOrString.fromNumber(1234),
+        scheme: 'HTTP',
       },
       initialDelaySeconds: undefined,
       periodSeconds: undefined,
@@ -63,6 +65,7 @@ describe('fromHttpGet()', () => {
       httpGet: {
         path: '/hello',
         port: IntOrString.fromNumber(5555),
+        scheme: 'HTTP',
       },
       failureThreshold: 11,
       initialDelaySeconds: 60,