Skip to content

Commit 1fd42b4

Browse files
fix: Revert "Merge pull request #499"
This reverts commit 18b68f3, reversing changes made to 809e536.
1 parent aef7965 commit 1fd42b4

File tree

9 files changed

+3
-168
lines changed

9 files changed

+3
-168
lines changed

test/fixtures/insecure-registries/push-dockerhub-image-to-local-registry.yaml

Lines changed: 0 additions & 22 deletions
This file was deleted.

test/fixtures/insecure-registries/python-local-deployment.yaml

Lines changed: 0 additions & 24 deletions
This file was deleted.

test/fixtures/insecure-registries/registries.conf

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/helpers/kubectl.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,6 @@ export async function createSecret(
6464
console.log(`Created secret ${secretName}`);
6565
}
6666

67-
export async function createConfigMap(
68-
configMapName: string,
69-
namespace: string,
70-
filePath: string
71-
): Promise<void> {
72-
console.log(`Creating config map ${configMapName} in namespace ${namespace}...`);
73-
await exec(`./kubectl create configmap ${configMapName} -n ${namespace} --from-file=${filePath}`);
74-
console.log(`Created config map ${configMapName}`);
75-
}
76-
7767
export async function applyK8sYaml(pathToYamlDeployment: string): Promise<void> {
7868
console.log(`Applying ${pathToYamlDeployment}...`);
7969
await exec(`./kubectl apply -f ${pathToYamlDeployment}`);
@@ -155,22 +145,6 @@ export async function waitForServiceAccount(name: string, namespace: string): Pr
155145
}
156146
}
157147

158-
export async function waitForJob(name: string, namespace: string): Promise<void> {
159-
console.log(`Trying to find job ${name} in namespace ${namespace}`);
160-
for (let attempt = 0; attempt < 60; attempt++) {
161-
try {
162-
await exec(`./kubectl get jobs/${name} -n ${namespace}`);
163-
} catch (error) {
164-
await sleep(1000);
165-
}
166-
}
167-
console.log(`Found job ${name} in namespace ${namespace}`);
168-
169-
console.log(`Begin waiting for job ${name} in namespace ${namespace} to complete`);
170-
await exec(`./kubectl wait --for=condition=complete jobs/${name} -n ${namespace} --timeout=240s`);
171-
console.log(`Job ${name} in namespace ${namespace} is complete`);
172-
}
173-
174148
async function getLatestStableK8sRelease(): Promise<string> {
175149
const k8sRelease = await needle('get',
176150
'https://storage.googleapis.com/kubernetes-release/release/stable.txt',

test/integration/kubernetes.test.ts

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { CoreV1Api, KubeConfig, AppsV1Api } from '@kubernetes/client-node';
2-
import { exec } from 'child-process-promise';
32
import setup = require('../setup');
43
import * as tap from 'tap';
54
import { WorkloadKind } from '../../src/supervisor/types';
@@ -22,12 +21,6 @@ tap.tearDown(async() => {
2221
console.log('Begin removing the snyk-monitor...');
2322
await setup.removeMonitor();
2423
console.log('Removed the snyk-monitor!');
25-
console.log('Begin removing local container registry...');
26-
await setup.removeLocalContainerRegistry();
27-
console.log('Removed local container registry');
28-
console.log('Begin removing "kind" network...');
29-
await setup.removeUnusedKindNetwork();
30-
console.log('Removed "kind" network');
3124
});
3225

3326
// Make sure this runs first -- deploying the monitor for the next tests
@@ -72,19 +65,6 @@ tap.test('snyk-monitor container started', async (t) => {
7265
console.log('Done -- snyk-monitor exists!');
7366
});
7467

75-
tap.test('create local container registry and push an image', async (t) => {
76-
console.log('Creating local container registry...');
77-
await exec('docker run -d --restart=always -p "5000:5000" --name "kind-registry" registry:2');
78-
await exec('docker network connect "kind" "kind-registry"');
79-
80-
console.log('Pushing python:rc-buster image to the local registry');
81-
//Note: this job takes a while and waitForJob() should be called before trying to access local registry image,
82-
//to make sure it completed
83-
await kubectl.applyK8sYaml('./test/fixtures/insecure-registries/push-dockerhub-image-to-local-registry.yaml');
84-
85-
t.pass('successfully started a job to push image to a local registry');
86-
});
87-
8868
tap.test('snyk-monitor sends data to kubernetes-upstream', async (t) => {
8969
t.plan(7);
9070

@@ -246,46 +226,6 @@ tap.test('snyk-monitor pulls images from a private ECR and sends data to kuberne
246226
'snyk-monitor sent expected data to upstream in the expected timeframe');
247227
});
248228

249-
tap.test('snyk-monitor pulls images from a local registry and sends data to kubernetes-upstream', async (t) => {
250-
t.plan(4);
251-
252-
const deploymentName = 'python-local';
253-
const namespace = 'services';
254-
const clusterName = 'Default cluster';
255-
const deploymentType = WorkloadKind.Deployment;
256-
const imageName = 'kind-registry:5000/python:rc-buster';
257-
258-
await kubectl.waitForJob('push-to-local-registry', 'default');
259-
260-
console.log('Applying local registry workload...');
261-
await kubectl.applyK8sYaml('./test/fixtures/insecure-registries/python-local-deployment.yaml');
262-
263-
console.log(`Begin polling upstream for the expected kind-registry:5000 image with integration ID ${integrationId}...`);
264-
265-
const validatorFn: WorkloadLocatorValidator = (workloads) => {
266-
return workloads !== undefined &&
267-
workloads.find((workload) => workload.name === deploymentName &&
268-
workload.type === WorkloadKind.Deployment) !== undefined;
269-
};
270-
271-
const testResult = await validateUpstreamStoredData(
272-
validatorFn, `api/v2/workloads/${integrationId}/${clusterName}/${namespace}`);
273-
t.ok(testResult, 'snyk-monitor sent expected data to upstream in the expected timeframe');
274-
275-
const depGraphResult = await getUpstreamResponseBody(
276-
`api/v1/dependency-graphs/${integrationId}/${clusterName}/${namespace}/${deploymentType}/${deploymentName}`);
277-
278-
t.ok('dependencyGraphResults' in depGraphResult,
279-
'expected dependencyGraphResults field to exist in /dependency-graphs response');
280-
281-
/* Because of a bug in removeTagFromImage() func in src/scanner/images/index.ts,
282-
which chops off everything after ':' from the image name, we store a wrong image name
283-
and the result does not exist in the object referred below */
284-
t.same(depGraphResult.dependencyGraphResults[imageName], null,
285-
'expected result for image kind-registry:5000/python:rc-buster does not exist');
286-
t.ok('kind-registry' in depGraphResult.dependencyGraphResults, 'BUG: the full image name is not stored in kubernetes-upstream');
287-
});
288-
289229
tap.test('snyk-monitor sends deleted workload to kubernetes-upstream', async (t) => {
290230
// First ensure the deployment exists from the previous test
291231
const deploymentValidatorFn: WorkloadLocatorValidator = (workloads) => {

test/setup/index.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as fs from 'fs';
22
import * as sleep from 'sleep-promise';
33
import * as uuidv4 from 'uuid/v4';
4-
import { exec } from 'child-process-promise';
54

65
import platforms, { getKubernetesVersionForPlatform } from './platforms';
76
import deployers from './deployers';
@@ -38,22 +37,6 @@ export async function removeMonitor(): Promise<void> {
3837
}
3938
}
4039

41-
export async function removeLocalContainerRegistry(): Promise<void> {
42-
try {
43-
await exec('docker rm kind-registry --force');
44-
} catch (error) {
45-
console.log(`Could not remove container registry, it probably did not exist: ${error.message}`);
46-
}
47-
}
48-
49-
export async function removeUnusedKindNetwork(): Promise<void> {
50-
try {
51-
await exec('docker network rm kind');
52-
} catch (error) {
53-
console.log(`Could not remove "kind" network: ${error.message}`);
54-
}
55-
}
56-
5740
async function createEnvironment(): Promise<void> {
5841
// TODO: we probably want to use k8s-api for that, not kubectl
5942
await kubectl.createNamespace('services');
@@ -73,7 +56,6 @@ async function predeploy(integrationId: string): Promise<void> {
7356
'dockercfg.json': gcrDockercfg,
7457
integrationId,
7558
});
76-
await createRegistriesConfigMap();
7759
} catch (error) {
7860
console.log('Could not create namespace and secret, they probably already exist');
7961
}
@@ -98,10 +80,6 @@ async function createSecretForGcrIoAccess(): Promise<void> {
9880
);
9981
}
10082

101-
async function createRegistriesConfigMap(): Promise<void> {
102-
await kubectl.createConfigMap('snyk-monitor-registries-conf', 'snyk-monitor', './test/fixtures/insecure-registries/registries.conf');
103-
}
104-
10583
export async function deployMonitor(): Promise<string> {
10684
console.log('Begin deploying the snyk-monitor...');
10785

test/setup/platforms/cluster-config.yaml

Lines changed: 0 additions & 6 deletions
This file was deleted.

test/setup/platforms/kind.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ export async function createCluster(version: string): Promise<void> {
2121
// which does not necessarily have the "latest" tag
2222
kindImageArgument = `--image="kindest/node:${kindImageTag}"`;
2323
}
24-
const clusterConfigPath = "test/setup/platforms/cluster-config.yaml";
25-
26-
await exec(`./kind create cluster --name="${clusterName}" ${kindImageArgument} --config="${clusterConfigPath}"`);
24+
await exec(`./kind create cluster --name="${clusterName}" ${kindImageArgument}`);
2725
console.log(`Created cluster ${clusterName}!`);
2826
}
2927

@@ -61,7 +59,7 @@ async function download(osDistro: string): Promise<void> {
6159
} catch (error) {
6260
console.log('Downloading KinD...');
6361

64-
const url = `https://github.com/kubernetes-sigs/kind/releases/download/v0.8.1/kind-${osDistro}-amd64`;
62+
const url = `https://github.com/kubernetes-sigs/kind/releases/download/v0.7.0/kind-${osDistro}-amd64`;
6563
await exec(`curl -Lo ./kind ${url}`);
6664
chmodSync('kind', 0o755); // rwxr-xr-x
6765

test/system/kind.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ tap.test('Kubernetes-Monitor with KinD', async (t) => {
3636
// linux-oriented, not mac
3737
// for mac, install skopeo with brew
3838
console.log('installing Skopeo');
39-
await exec('git clone --depth 1 -b "v0.2.0" https://github.com/containers/skopeo');
39+
await exec('git clone https://github.com/containers/skopeo');
4040
await exec('(cd skopeo && make binary-static DISABLE_CGO=1)');
4141
await exec('sudo mkdir -p /etc/containers');
4242
await exec('sudo chown circleci:circleci /etc/containers');

0 commit comments

Comments
 (0)