Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(provider/kubernetes): v1 fix red/black for svgs without lbs #2317

Merged
merged 1 commit into from
Jan 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,22 @@ class KubernetesApiAdaptor {
}
}

void annotateReplicaSet(String namespace, String name, String key, String value) {
exceptionWrapper("replicaSets.annotate", "Annotate replica set $name", namespace) {
def rs = client.extensions().replicaSets().inNamespace(namespace).withName(name).edit()
rs.buildMetadata().annotations?.put(key, value)
rs.done()
}
}

void annotateReplicationController(String namespace, String name, String key, String value) {
exceptionWrapper("replicationControllers.annotate", "Annotate replication controller $name", namespace) {
def rc = client.replicationControllers().inNamespace(namespace).withName(name).edit()
rc.buildMetadata().annotations?.put(key, value)
rc.done()
}
}

boolean deleteDeployment(String namespace, String name) {
exceptionWrapper("deployments.delete", "Delete Deployment $name", namespace) {
client.extensions().deployments().inNamespace(namespace).withName(name).delete()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class KubernetesUtil {
private static int SECURITY_GROUP_LABEL_PREFIX_LENGTH = SECURITY_GROUP_LABEL_PREFIX.length()
private static int LOAD_BALANCER_LABEL_PREFIX_LENGTH = LOAD_BALANCER_LABEL_PREFIX.length()

static String ENABLE_DISABLE_ANNOTATION = "service.spinnaker.io/enabled"

static String getNextSequence(String clusterName, String namespace, KubernetesV1Credentials credentials) {
def maxSeqNumber = -1
def replicationControllers = credentials.apiAdaptor.getReplicationControllers(namespace)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ abstract class AbstractEnableDisableKubernetesAtomicOperation implements AtomicO
def getResource = null
def desired = null
if (replicationController) {
credentials.apiAdaptor.annotateReplicationController(namespace, description.serverGroupName, KubernetesUtil.ENABLE_DISABLE_ANNOTATION, action)
desired = credentials.apiAdaptor.toggleReplicationControllerSpecLabels(namespace, description.serverGroupName, services, action)
getGeneration = { ReplicationController rc ->
return rc.metadata.generation
Expand All @@ -97,6 +98,7 @@ abstract class AbstractEnableDisableKubernetesAtomicOperation implements AtomicO
return credentials.apiAdaptor.getReplicationController(namespace, description.serverGroupName)
}
} else if (replicaSet) {
credentials.apiAdaptor.annotateReplicaSet(namespace, description.serverGroupName, KubernetesUtil.ENABLE_DISABLE_ANNOTATION, action)
desired = credentials.apiAdaptor.toggleReplicaSetSpecLabels(namespace, description.serverGroupName, services, action)
getGeneration = { ReplicaSet rs ->
return rs.metadata.generation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import io.fabric8.kubernetes.client.internal.SerializationUtils
import io.kubernetes.client.models.V1beta1DaemonSet
import io.kubernetes.client.models.V1beta1StatefulSet

import static com.netflix.spinnaker.clouddriver.kubernetes.v1.deploy.KubernetesUtil.ENABLE_DISABLE_ANNOTATION

@CompileStatic
@EqualsAndHashCode(includes = ["name", "namespace", "account"])
class KubernetesV1ServerGroup implements ServerGroup, Serializable {
Expand All @@ -55,6 +57,7 @@ class KubernetesV1ServerGroup implements ServerGroup, Serializable {
Set<String> securityGroups = [] as Set
Map<String, Object> launchConfig
Map<String, String> labels = [:]
Map<String, String> annotations = [:]
DeployKubernetesAtomicOperationDescription deployDescription
KubernetesAutoscalerStatus autoscalerStatus
KubernetesDeploymentStatus deploymentStatus
Expand Down Expand Up @@ -92,7 +95,7 @@ class KubernetesV1ServerGroup implements ServerGroup, Serializable {
if (labels) {
def lbCount = labels.count { key, value -> KubernetesUtil.isLoadBalancerLabel(key) }
if (lbCount == 0) {
return false
return annotations?.get(ENABLE_DISABLE_ANNOTATION) == "false"
}

def enabledCount = labels.count { key, value -> KubernetesUtil.isLoadBalancerLabel(key) && value == "true" }
Expand Down Expand Up @@ -162,6 +165,7 @@ class KubernetesV1ServerGroup implements ServerGroup, Serializable {
this.deployDescription = KubernetesApiConverter.fromReplicaSet(replicaSet)
this.yaml = SerializationUtils.dumpWithoutRuntimeStateAsYaml(replicaSet)
this.kind = replicaSet.kind
this.annotations = replicaSet.metadata?.annotations
this.events = events?.collect {
new KubernetesEvent(it)
}
Expand All @@ -187,6 +191,7 @@ class KubernetesV1ServerGroup implements ServerGroup, Serializable {
this.deployDescription = KubernetesApiConverter.fromReplicationController(replicationController)
this.yaml = SerializationUtils.dumpWithoutRuntimeStateAsYaml(replicationController)
this.kind = replicationController.kind
this.annotations = replicationController.metadata?.annotations
this.events = events?.collect {
new KubernetesEvent(it)
}
Expand Down