Skip to content

Commit

Permalink
Merge pull request #259 from lensapp/https-proxy-env
Browse files Browse the repository at this point in the history
Https proxy env
  • Loading branch information
samitiilikainen authored Dec 12, 2023
2 parents c4cea6b + e8522b7 commit 364454a
Show file tree
Hide file tree
Showing 7 changed files with 427 additions and 122 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"lodash": "^4.17.21",
"pino": "^6.13.2",
"pino-pretty": "^7.5.1",
"ws": "^7.5.6"
"ws": "^7.5.6",
"yaml": "^2.3.4"
}
}
94 changes: 94 additions & 0 deletions src/__tests__/__snapshots__/updater-yml.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`updater parses yaml 1`] = `
"apiVersion: v1
kind: Namespace
metadata:
name: lens-platform
---
apiVersion: v1
kind: ConfigMap
metadata:
name: lens-platform-cluster
namespace: lens-platform
data:
lensPlatformK8sclusterId: some-LENS_PLATFORM_K8S_CLUSTER_ID
lensPlatformSpaceName: some-LENS_PLATFORM_SPACE_NAME
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: bored-agent-updater
namespace: lens-platform
spec:
schedule: \\"@hourly\\"
jobTemplate:
spec:
template:
spec:
serviceAccountName: bored-agent-updater
containers:
- name: bored-agent-updater
image: quay.io/k8slens/bored-agent:0.10.0
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: BORED_SERVER
value: some-BORED_SERVER
- name: BORED_TOKEN
value: some-BORED_TOKEN
- name: LENS_PLATFORM_K8S_CLUSTER_ID
value: some-LENS_PLATFORM_K8S_CLUSTER_ID
- name: LENS_PLATFORM_SPACE_NAME
value: some-LENS_PLATFORM_SPACE_NAME
- name: LENS_BACKEND_URL
value: https://some-url.irrelevant/
- name: AUTO_UPDATE_URL
value: https://some-url.irrelevant/some-file-path
- name: BORED_HTTPS_PROXY
value: some-BORED_HTTPS_PROXY
command:
- node
- dist/src/updater.js
restartPolicy: Never
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: bored-agent
namespace: lens-platform
labels:
app: bored-agent
spec:
replicas: 1
selector:
matchLabels:
app: bored-agent
template:
metadata:
labels:
app: bored-agent
spec:
priorityClassName: lens-bored-agent
serviceAccountName: bored-agent
containers:
- name: agent
image: quay.io/k8slens/bored-agent:0.10.0
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: BORED_SERVER
value: some-BORED_SERVER
- name: BORED_TOKEN
value: some-BORED_TOKEN
- name: HTTPS_PROXY
value: some-HTTPS_PROXY
"
`;
88 changes: 88 additions & 0 deletions src/__tests__/updater-mock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
apiVersion: v1
kind: Namespace
metadata:
name: lens-platform
---
apiVersion: v1
kind: ConfigMap
metadata:
name: lens-platform-cluster
namespace: lens-platform
data:
lensPlatformK8sclusterId: $LENS_PLATFORM_K8S_CLUSTER_ID
lensPlatformSpaceName: $LENS_PLATFORM_SPACE_NAME
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: bored-agent-updater
namespace: lens-platform
spec:
schedule: "@hourly"
jobTemplate:
spec:
template:
spec:
serviceAccountName: bored-agent-updater
containers:
- name: bored-agent-updater
image: quay.io/k8slens/bored-agent:0.10.0
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: BORED_SERVER
value: $BORED_SERVER
- name: BORED_TOKEN
value: $BORED_TOKEN
- name: LENS_PLATFORM_K8S_CLUSTER_ID
value: $LENS_PLATFORM_K8S_CLUSTER_ID
- name: LENS_PLATFORM_SPACE_NAME
value: $LENS_PLATFORM_SPACE_NAME
- name: LENS_BACKEND_URL
value: $LENS_BACKEND_URL
- name: AUTO_UPDATE_URL
value: $AUTO_UPDATE_URL
- name: BORED_HTTPS_PROXY
value: ""
command:
- node
- dist/src/updater.js
restartPolicy: Never
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: bored-agent
namespace: lens-platform
labels:
app: bored-agent
spec:
replicas: 1
selector:
matchLabels:
app: bored-agent
template:
metadata:
labels:
app: bored-agent
spec:
priorityClassName: "lens-bored-agent"
serviceAccountName: bored-agent
containers:
- name: agent
image: quay.io/k8slens/bored-agent:0.10.0
env:
- name: NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: BORED_SERVER
value: $BORED_SERVER
- name: BORED_TOKEN
value: $BORED_TOKEN
- name: HTTPS_PROXY
value: ""
---

34 changes: 34 additions & 0 deletions src/__tests__/updater-yml.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import path from "path";
import { Config, fetchBoredAgentYml } from "../updater-yml";
import fs from "fs";

describe("updater", () => {
let config: Config;
let gotMock: jest.Mock;

beforeEach(() => {
config = {
BORED_SERVER: "some-BORED_SERVER",
BORED_TOKEN: "some-BORED_TOKEN",
LENS_PLATFORM_K8S_CLUSTER_ID: "some-LENS_PLATFORM_K8S_CLUSTER_ID",
LENS_PLATFORM_SPACE_NAME: "some-LENS_PLATFORM_SPACE_NAME",
NAMESPACE: "some-NAMESPACE",
AUTO_UPDATE_URL: "https://some-url.irrelevant/some-file-path",
LENS_BACKEND_URL: "https://some-url.irrelevant/",
HTTPS_PROXY: "some-HTTPS_PROXY",
BORED_HTTPS_PROXY: "some-BORED_HTTPS_PROXY",
};

const mockData = fs.readFileSync(
path.join(__dirname, "./updater-mock.yml")
);

gotMock = jest.fn().mockResolvedValue({ body: mockData.toString() });
});

it("parses yaml", async () => {
const result = await fetchBoredAgentYml(config, gotMock as any);

expect(result).toMatchSnapshot();
});
});
Loading

0 comments on commit 364454a

Please sign in to comment.