Skip to content

Conversation

@ivanstanev
Copy link
Contributor

@ivanstanev ivanstanev commented Apr 19, 2021

  • Tests written and linted ℹ︎
  • Documentation written ℹ︎
  • Commit history is tidy ℹ︎

What this does

Add support for DeploymentConfig on OpenShift.

Before we set up Informers in the cluster for all the different workloads (e.g. Deployment, ReplicaSet), specifically for DeploymentConfig we now do a small query to the API server to understand if it's supported. If the API request returns successfully (non-404 code) then DeploymentConfig is supported and we set up a Watch following the routes in the API reference. If the K8s API returns 404 (meaning the resource is unknown) then we skip creating a DeploymentConfig Informer.

What was added:

  • an integration test for OpenShift 4 that applies a DeploymentConfig and checks that the workload was scanned
  • TypeScript types for DeploymentConfigV1 based on the API reference
  • some functions are now async to allow querying the API server for supported workloads before deciding whether to set an Informer; we also await informer.start() calls since it returns a Promise

More information

Commit by commit 🙏

@ivanstanev ivanstanev self-assigned this Apr 19, 2021
@ivanstanev ivanstanev requested a review from a team as a code owner April 19, 2021 14:58
@ivanstanev ivanstanev force-pushed the feat/deployment-config branch from f08991f to 7ce2834 Compare April 19, 2021 15:13
}

export async function setupInformer(namespace: string, workloadKind: WorkloadKind): Promise<void> {
const isSupported = await isSupportedWorkload(namespace, workloadKind);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is workload support supposed to be cluster-wide check, not per ns?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡
But it would complicate the code a bit, we now need to check this only once and we need to differentiate between snyk-monitor scanning the cluster or snyk-monitor scanning a single namespace (won't have permission to query the cluster if scanning a single namespace).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opting not to do it because it would complicate the code quite a bit, LMK if you think it's a really bad idea and the benefits would outweigh the downsides 😉

const resourceVersion = undefined; // List anything in the cluster
const timeoutSeconds = 10; // Don't block the snyk-monitor indefinitely
const attemptedApiCall = await k8sApi.customObjectsClient.listNamespacedCustomObject(
'apps.openshift.io',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Why don't store this in an object and just reference GVK parts from the static map?

Copy link
Contributor Author

@ivanstanev ivanstanev Apr 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you share example code? Not sure what you mean

The snyk-monitor will do a best-effort attempt to set up a Watch/Informer for DeploymentConfigs in the apps.openshift.io/v1 API. If this does not succeed, scanning will proceed as normal while printing a warning.
This reverts the change in 07f4f34.
DeploymentConfigs on OpenShift create ReplicationControllers which in turn create Pods. However, the ReplicationControllers in this case are not marked as controllers, hence we cannot walk the list of owner references and can never scan DeploymentConfigs.

This change ensures we do not strictly check for controllers to allow us to read DeploymentConfigs.
@ivanstanev ivanstanev force-pushed the feat/deployment-config branch from 7ce2834 to 9c08163 Compare April 19, 2021 16:45
@github-actions
Copy link

github-actions bot commented Apr 19, 2021

Expected release notes (by @ivanstanev)

features:
add DeploymentConfig support for OpenShift (3b9c842)

fixes:
revert checking for parent workloads being controllers (9c08163)
upgrade kubernetes/client-node to remove net-keepalive dependency (eae1eb7)
log the Promise for debugging when an unhandledRejections occur (d39d9ba)

  • I hereby acknowledge these release notes are 🥙 AWESOME 🥙

@ivanstanev ivanstanev merged commit 19b6341 into staging Apr 21, 2021
@ivanstanev ivanstanev deleted the feat/deployment-config branch April 21, 2021 11:17
@snyksec
Copy link

snyksec commented Apr 21, 2021

🎉 This PR is included in version 1.51.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants