Skip to content

Commit

Permalink
fix(kubernetes): Add networking.k8s.io/v1beta1 ingress versions (#4056)
Browse files Browse the repository at this point in the history
* refactor(kubernetes): Pull api versions to a set

A number of different places check the API version of a manifest
against a set of supported ones using a log if condition. Replace
these with a statically-defined set of supported versions and a
check of whether the manifest's API version is in the set.

This commit doesn't change any of the supported versions.

* fix(kubernetes): Add networking.k8s.io/v1beta1 ingress versions

In Kubernetes 1.20, Ingress will stop being served from the
extensions/v1beta1 API group and will only be served from the
networking.k8s.io/v1beta1 API group (which has been available
since 1.14).
  • Loading branch information
ezimanyi authored Sep 26, 2019
1 parent 4c907ee commit e1fa111
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import static com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesApiVersion.NETWORKING_K8S_IO_V1;
import static com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesApiVersion.NETWORKING_K8S_IO_V1BETA1;

import com.google.common.collect.ImmutableSet;
import com.netflix.spinnaker.cats.cache.CacheData;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.Keys;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.agent.KubernetesCacheDataConverter;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesApiVersion;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesKind;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesManifest;
import com.netflix.spinnaker.clouddriver.model.SecurityGroup;
Expand All @@ -47,6 +49,9 @@
@Data
@Slf4j
public class KubernetesV2SecurityGroup extends ManifestBasedModel implements SecurityGroup {
private static final ImmutableSet<KubernetesApiVersion> SUPPORTED_API_VERSIONS =
ImmutableSet.of(NETWORKING_K8S_IO_V1BETA1, NETWORKING_K8S_IO_V1);

private KubernetesManifest manifest;
private Keys.InfrastructureCacheKey key;
private String id;
Expand Down Expand Up @@ -91,8 +96,7 @@ public static KubernetesV2SecurityGroup fromCacheData(CacheData cd) {
if (!manifest.getKind().equals(KubernetesKind.NETWORK_POLICY)) {
log.warn("Unknown security group kind " + manifest.getKind());
} else {
if (manifest.getApiVersion().equals(NETWORKING_K8S_IO_V1)
|| (manifest.getApiVersion().equals(NETWORKING_K8S_IO_V1BETA1))) {
if (SUPPORTED_API_VERSIONS.contains(manifest.getApiVersion())) {
V1NetworkPolicy v1beta1NetworkPolicy =
KubernetesCacheDataConverter.getResource(manifest, V1NetworkPolicy.class);
inboundRules = inboundRules(v1beta1NetworkPolicy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
import static com.netflix.spinnaker.clouddriver.kubernetes.v2.op.handler.KubernetesHandler.DeployPriority.WORKLOAD_CONTROLLER_PRIORITY;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.netflix.spinnaker.clouddriver.kubernetes.description.SpinnakerKind;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.artifact.Replacer;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.agent.KubernetesCacheDataConverter;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.agent.KubernetesCoreCachingAgent;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.agent.KubernetesV2CachingAgentFactory;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesApiVersion;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesKind;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesManifest;
import com.netflix.spinnaker.clouddriver.model.Manifest.Status;
Expand All @@ -47,6 +49,9 @@ public class KubernetesDeploymentHandler extends KubernetesHandler
CanUndoRollout,
ServerGroupManagerHandler {

private static final ImmutableSet<KubernetesApiVersion> SUPPORTED_API_VERSIONS =
ImmutableSet.of(EXTENSIONS_V1BETA1, APPS_V1BETA1, APPS_V1BETA2, APPS_V1);

@Nonnull
@Override
protected ImmutableList<Replacer> artifactReplacers() {
Expand Down Expand Up @@ -84,19 +89,15 @@ public SpinnakerKind spinnakerKind() {

@Override
public Status status(KubernetesManifest manifest) {
if (manifest.getApiVersion().equals(EXTENSIONS_V1BETA1)
|| manifest.getApiVersion().equals(APPS_V1BETA1)
|| manifest.getApiVersion().equals(APPS_V1BETA2)
|| manifest.getApiVersion().equals(APPS_V1)) {
if (manifest.isNewerThanObservedGeneration()) {
return (new Status()).unknown();
}
V1Deployment appsV1Deployment =
KubernetesCacheDataConverter.getResource(manifest, V1Deployment.class);
return status(appsV1Deployment);
} else {
if (!SUPPORTED_API_VERSIONS.contains(manifest.getApiVersion())) {
throw new UnsupportedVersionException(manifest);
}
if (manifest.isNewerThanObservedGeneration()) {
return (new Status()).unknown();
}
V1Deployment appsV1Deployment =
KubernetesCacheDataConverter.getResource(manifest, V1Deployment.class);
return status(appsV1Deployment);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@
package com.netflix.spinnaker.clouddriver.kubernetes.v2.op.handler;

import static com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesApiVersion.EXTENSIONS_V1BETA1;
import static com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesApiVersion.NETWORKING_K8S_IO_V1BETA1;
import static com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesKind.INGRESS;
import static com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesKind.SERVICE;
import static com.netflix.spinnaker.clouddriver.kubernetes.v2.op.handler.KubernetesHandler.DeployPriority.NETWORK_RESOURCE_PRIORITY;

import com.google.common.collect.ImmutableSet;
import com.netflix.spinnaker.clouddriver.kubernetes.description.SpinnakerKind;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.Keys;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.agent.KubernetesCacheDataConverter;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.agent.KubernetesCoreCachingAgent;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.agent.KubernetesV2CachingAgentFactory;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.view.provider.KubernetesCacheUtils;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesApiVersion;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesKind;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesManifest;
import com.netflix.spinnaker.clouddriver.model.Manifest.Status;
Expand All @@ -47,6 +50,9 @@
@Component
@Slf4j
public class KubernetesIngressHandler extends KubernetesHandler {
private static final ImmutableSet<KubernetesApiVersion> SUPPORTED_API_VERSIONS =
ImmutableSet.of(EXTENSIONS_V1BETA1, NETWORKING_K8S_IO_V1BETA1);

@Override
public int deployPriority() {
return NETWORK_RESOURCE_PRIORITY.getValue();
Expand Down Expand Up @@ -110,13 +116,12 @@ public void addRelationships(
}

private static List<String> attachedServices(KubernetesManifest manifest) {
if (manifest.getApiVersion().equals(EXTENSIONS_V1BETA1)) {
V1beta1Ingress v1beta1Ingress =
KubernetesCacheDataConverter.getResource(manifest, V1beta1Ingress.class);
return attachedServices(v1beta1Ingress);
} else {
if (!SUPPORTED_API_VERSIONS.contains(manifest.getApiVersion())) {
throw new UnsupportedVersionException(manifest);
}
V1beta1Ingress v1beta1Ingress =
KubernetesCacheDataConverter.getResource(manifest, V1beta1Ingress.class);
return attachedServices(v1beta1Ingress);
}

private static List<String> attachedServices(V1beta1Ingress ingress) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
import static com.netflix.spinnaker.clouddriver.kubernetes.v2.op.handler.KubernetesHandler.DeployPriority.WORKLOAD_CONTROLLER_PRIORITY;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.netflix.spinnaker.clouddriver.kubernetes.description.SpinnakerKind;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.artifact.Replacer;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.Keys;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.agent.KubernetesCacheDataConverter;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.agent.KubernetesCoreCachingAgent;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.agent.KubernetesV2CachingAgentFactory;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.view.provider.KubernetesCacheUtils;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesApiVersion;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesKind;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesManifest;
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesManifestSelector;
Expand All @@ -49,6 +51,9 @@
@Component
public class KubernetesReplicaSetHandler extends KubernetesHandler
implements CanResize, CanScale, HasPods, ServerGroupHandler {
private static final ImmutableSet<KubernetesApiVersion> SUPPORTED_API_VERSIONS =
ImmutableSet.of(EXTENSIONS_V1BETA1, APPS_V1BETA2, APPS_V1);

@Nonnull
@Override
protected ImmutableList<Replacer> artifactReplacers() {
Expand Down Expand Up @@ -91,15 +96,12 @@ protected KubernetesV2CachingAgentFactory cachingAgentFactory() {

@Override
public Status status(KubernetesManifest manifest) {
if (manifest.getApiVersion().equals(EXTENSIONS_V1BETA1)
|| manifest.getApiVersion().equals(APPS_V1BETA2)
|| manifest.getApiVersion().equals(APPS_V1)) {
V1ReplicaSet v1ReplicaSet =
KubernetesCacheDataConverter.getResource(manifest, V1ReplicaSet.class);
return status(v1ReplicaSet);
} else {
if (!SUPPORTED_API_VERSIONS.contains(manifest.getApiVersion())) {
throw new UnsupportedVersionException(manifest);
}
V1ReplicaSet v1ReplicaSet =
KubernetesCacheDataConverter.getResource(manifest, V1ReplicaSet.class);
return status(v1ReplicaSet);
}

private Status status(V1ReplicaSet replicaSet) {
Expand Down

0 comments on commit e1fa111

Please sign in to comment.