Skip to content

Commit 794c0e3

Browse files
authored
Merge pull request #930 from snyk/feat/operator-resources
Feat/operator resources
2 parents 0d8684f + b8ecc7f commit 794c0e3

File tree

19 files changed

+686
-46
lines changed

19 files changed

+686
-46
lines changed

scripts/operator/package_operator_bundle.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ def createOperatorFromTemplate(new_version: str, new_operator_tag: str, new_moni
3636
'SNYK_OPERATOR_VERSION_OVERRIDE', new_version).replace(
3737
'SNYK_OPERATOR_IMAGE_TAG_OVERRIDE', new_operator_tag).replace(
3838
'SNYK_MONITOR_IMAGE_TAG_OVERRIDE', new_monitor_tag)
39-
# TODO: Uncomment (or revert commit) once v1.68.2 is published in OperatorHub
40-
# if old_version != None:
41-
# updated_csv = updated_csv + " replaces: snyk-operator.v" + old_version
39+
if old_version != None:
40+
updated_csv = updated_csv + " replaces: snyk-operator.v" + old_version
4241
with open(new_csv_path, "w") as f:
4342
f.write(updated_csv)
4443

snyk-operator-certified/bundle/manifests/snyk-monitor.clusterserviceversion.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ metadata:
3535
"pvc": {
3636
"enabled": false,
3737
"name": "snyk-monitor"
38+
},
39+
"requests": {
40+
"memory": "400Mi"
41+
},
42+
"limits": {
43+
"memory": "2Gi"
3844
}
3945
}
4046
}
@@ -118,6 +124,18 @@ spec:
118124
path: initContainerImage.image
119125
x-descriptors:
120126
- urn:alm:descriptor:text
127+
- description: >-
128+
The memory requested by the Snyk controller.
129+
displayName: Memory request
130+
path: requests.memory
131+
x-descriptors:
132+
- "urn:alm:descriptor:text"
133+
- description: >-
134+
The memory limit for the Snyk controller.
135+
displayName: Memory limit
136+
path: limits.memory
137+
x-descriptors:
138+
- "urn:alm:descriptor:text"
121139
version: v1alpha1
122140
description: |-
123141
A Kubernetes Operator for creating and managing Snyk Kubernetes controller instances.

snyk-operator-certified/config/manifests/bases/snyk-monitor.clusterserviceversion.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ metadata:
2828
"initContainerImage": {
2929
"repository": "registry.access.redhat.com/ubi8-minimal",
3030
"tag": "latest"
31+
},
32+
"requests": {
33+
"memory": "400Mi"
34+
},
35+
"limits": {
36+
"memory": "2Gi"
3137
}
3238
}
3339
}
@@ -100,6 +106,18 @@ spec:
100106
path: image.tag
101107
x-descriptors:
102108
- urn:alm:descriptor:text
109+
- description: >-
110+
The memory requested by the Snyk controller.
111+
displayName: Memory request
112+
path: requests.memory
113+
x-descriptors:
114+
- "urn:alm:descriptor:text"
115+
- description: >-
116+
The memory limit for the Snyk controller.
117+
displayName: Memory limit
118+
path: limits.memory
119+
x-descriptors:
120+
- "urn:alm:descriptor:text"
103121
version: v1alpha1
104122
description: |-
105123
A Kubernetes Operator for creating and managing Snyk Kubernetes controller instances.

snyk-operator/deploy/olm-catalog/snyk-operator/0.0.0/snyk-operator.v0.0.0.clusterserviceversion.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ metadata:
3030
"initContainerImage": {
3131
"repository": "busybox",
3232
"tag": "latest"
33+
},
34+
"requests": {
35+
"memory": "400Mi"
36+
},
37+
"limits": {
38+
"memory": "2Gi"
3339
}
3440
}
3541
}
@@ -153,6 +159,18 @@ spec:
153159
path: initContainerImage.tag
154160
x-descriptors:
155161
- "urn:alm:descriptor:text"
162+
- description: >-
163+
The memory requested by the Snyk controller.
164+
displayName: Memory request
165+
path: requests.memory
166+
x-descriptors:
167+
- "urn:alm:descriptor:text"
168+
- description: >-
169+
The memory limit for the Snyk controller.
170+
displayName: Memory limit
171+
path: limits.memory
172+
x-descriptors:
173+
- "urn:alm:descriptor:text"
156174
description: |-
157175
A Kubernetes Operator for creating and managing Snyk Kubernetes controller instances.
158176

snyk-operator/deploy/olm-catalog/snyk-operator/0.0.0/snykmonitors.charts.helm.k8s.io.crd.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,13 @@ spec:
7171
tag:
7272
type: string
7373
type: object
74+
requests:
75+
properties:
76+
memory:
77+
type: string
78+
type: object
79+
limits:
80+
properties:
81+
memory:
82+
type: string
83+
type: object

src/supervisor/kuberenetes-api-wrappers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export async function retryKubernetesApiRequestIndefinitely<ResponseType>(
7171
}
7272

7373
export function calculateSleepSeconds(
74-
httpResponse: http.IncomingMessage,
74+
httpResponse?: http.IncomingMessage,
7575
): number {
7676
let sleepSeconds = DEFAULT_SLEEP_SEC;
7777
if (

src/supervisor/watchers/handlers/cron-job.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
1-
import { V1beta1CronJob } from '@kubernetes/client-node';
1+
import { V1beta1CronJob, V1beta1CronJobList } from '@kubernetes/client-node';
22
import { deleteWorkload } from './workload';
33
import { WorkloadKind } from '../../types';
44
import { FALSY_WORKLOAD_NAME_MARKER } from './types';
5+
import { IncomingMessage } from 'http';
6+
import { k8sApi } from '../../cluster';
7+
import { paginatedList } from './pagination';
8+
9+
export async function paginatedCronJobList(namespace: string): Promise<{
10+
response: IncomingMessage;
11+
body: V1beta1CronJobList;
12+
}> {
13+
const v1CronJobList = new V1beta1CronJobList();
14+
v1CronJobList.apiVersion = 'batch/v1beta1';
15+
v1CronJobList.kind = 'CronJobList';
16+
v1CronJobList.items = new Array<V1beta1CronJob>();
17+
18+
return await paginatedList(
19+
namespace,
20+
v1CronJobList,
21+
k8sApi.batchUnstableClient.listNamespacedCronJob.bind(
22+
k8sApi.batchUnstableClient,
23+
),
24+
);
25+
}
526

627
export async function cronJobWatchHandler(
728
cronJob: V1beta1CronJob,

src/supervisor/watchers/handlers/daemon-set.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
1-
import { V1DaemonSet } from '@kubernetes/client-node';
1+
import { V1DaemonSet, V1DaemonSetList } from '@kubernetes/client-node';
22
import { deleteWorkload } from './workload';
33
import { WorkloadKind } from '../../types';
44
import { FALSY_WORKLOAD_NAME_MARKER } from './types';
5+
import { IncomingMessage } from 'http';
6+
import { k8sApi } from '../../cluster';
7+
import { paginatedList } from './pagination';
8+
9+
export async function paginatedDaemonSetList(namespace: string): Promise<{
10+
response: IncomingMessage;
11+
body: V1DaemonSetList;
12+
}> {
13+
const v1DaemonSetList = new V1DaemonSetList();
14+
v1DaemonSetList.apiVersion = 'apps/v1';
15+
v1DaemonSetList.kind = 'DaemonSetList';
16+
v1DaemonSetList.items = new Array<V1DaemonSet>();
17+
18+
return await paginatedList(
19+
namespace,
20+
v1DaemonSetList,
21+
k8sApi.appsClient.listNamespacedDaemonSet.bind(k8sApi.appsClient),
22+
);
23+
}
524

625
export async function daemonSetWatchHandler(
726
daemonSet: V1DaemonSet,

src/supervisor/watchers/handlers/deployment-config.ts

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,50 @@
1+
import { IncomingMessage } from 'http';
12
import { deleteWorkload } from './workload';
23
import { WorkloadKind } from '../../types';
3-
import { FALSY_WORKLOAD_NAME_MARKER, V1DeploymentConfig } from './types';
4+
import {
5+
FALSY_WORKLOAD_NAME_MARKER,
6+
V1DeploymentConfig,
7+
V1DeploymentConfigList,
8+
} from './types';
9+
import { paginatedList } from './pagination';
10+
import { k8sApi } from '../../cluster';
11+
12+
export async function paginatedDeploymentConfigList(
13+
namespace: string,
14+
): Promise<{
15+
response: IncomingMessage;
16+
body: V1DeploymentConfigList;
17+
}> {
18+
const v1DeploymentConfigList = new V1DeploymentConfigList();
19+
v1DeploymentConfigList.apiVersion = 'apps.openshift.io/v1';
20+
v1DeploymentConfigList.kind = 'DeploymentConfigList';
21+
v1DeploymentConfigList.items = new Array<V1DeploymentConfig>();
22+
23+
return await paginatedList(
24+
namespace,
25+
v1DeploymentConfigList,
26+
async (
27+
namespace: string,
28+
pretty?: string,
29+
_allowWatchBookmarks?: boolean,
30+
_continue?: string,
31+
fieldSelector?: string,
32+
labelSelector?: string,
33+
limit?: number,
34+
) =>
35+
k8sApi.customObjectsClient.listNamespacedCustomObject(
36+
'apps.openshift.io',
37+
'v1',
38+
namespace,
39+
'deploymentconfigs',
40+
pretty,
41+
_continue,
42+
fieldSelector,
43+
labelSelector,
44+
limit,
45+
) as any,
46+
);
47+
}
448

549
export async function deploymentConfigWatchHandler(
650
deploymentConfig: V1DeploymentConfig,

src/supervisor/watchers/handlers/deployment.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
1-
import { V1Deployment } from '@kubernetes/client-node';
1+
import { V1Deployment, V1DeploymentList } from '@kubernetes/client-node';
22
import { deleteWorkload } from './workload';
33
import { WorkloadKind } from '../../types';
44
import { FALSY_WORKLOAD_NAME_MARKER } from './types';
5+
import { IncomingMessage } from 'http';
6+
import { k8sApi } from '../../cluster';
7+
import { paginatedList } from './pagination';
8+
9+
export async function paginatedDeploymentList(namespace: string): Promise<{
10+
response: IncomingMessage;
11+
body: V1DeploymentList;
12+
}> {
13+
const v1DeploymentList = new V1DeploymentList();
14+
v1DeploymentList.apiVersion = 'apps/v1';
15+
v1DeploymentList.kind = 'DeploymentList';
16+
v1DeploymentList.items = new Array<V1Deployment>();
17+
18+
return await paginatedList(
19+
namespace,
20+
v1DeploymentList,
21+
k8sApi.appsClient.listNamespacedDeployment.bind(k8sApi.appsClient),
22+
);
23+
}
524

625
export async function deploymentWatchHandler(
726
deployment: V1Deployment,

0 commit comments

Comments
 (0)