Skip to content

Commit

Permalink
fix(provider/kuberentes): v1 fix scaleTargetRef apiVersion in HPA (#2249
Browse files Browse the repository at this point in the history
) (#2418)
  • Loading branch information
axot authored and lwander committed Mar 16, 2018
1 parent bb5888e commit 3eac933
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,8 @@ class KubernetesApiConverter {
static HorizontalPodAutoscalerFluentImpl toAutoscaler(HorizontalPodAutoscalerFluentImpl autoscalerBuilder,
KubernetesAutoscalerDescription description,
String resourceName,
String resourceKind) {
String resourceKind,
String apiVersion) {
autoscalerBuilder.withNewMetadata()
.withName(resourceName)
.withNamespace(description.namespace)
Expand All @@ -816,6 +817,7 @@ class KubernetesApiConverter {
.withNewScaleTargetRef()
.withKind(resourceKind)
.withName(resourceName)
.withApiVersion(apiVersion)
.endScaleTargetRef()
.endSpec()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class UpsertKubernetesAutoscalerAtomicOperation implements AtomicOperation<Void>
def hasDeployment = credentials.apiAdaptor.hasDeployment(replicaSet)
def name = hasDeployment ? parsedName.cluster : serverGroupName
def kind = hasDeployment ? KubernetesUtil.DEPLOYMENT_KIND : KubernetesUtil.SERVER_GROUP_KIND
def version = hasDeployment ? credentials.apiAdaptor.getDeployment(namespace, parsedName.cluster).getApiVersion() : replicaSet.getApiVersion()

task.updateStatus BASE_PHASE, "Looking up existing autoscaler..."

Expand All @@ -83,7 +84,7 @@ class UpsertKubernetesAutoscalerAtomicOperation implements AtomicOperation<Void>
autoscaler.spec.targetCPUUtilizationPercentage

((DoneableHorizontalPodAutoscaler) KubernetesApiConverter.toAutoscaler(
credentials.apiAdaptor.editAutoscaler(namespace, name), description, name, kind
credentials.apiAdaptor.editAutoscaler(namespace, name), description, name, kind, version
)).done()
} else {
if (!description.scalingPolicy || !description.scalingPolicy.cpuUtilization || description.scalingPolicy.cpuUtilization.target == null) {
Expand All @@ -95,7 +96,7 @@ class UpsertKubernetesAutoscalerAtomicOperation implements AtomicOperation<Void>
}

task.updateStatus BASE_PHASE, "Creating autoscaler..."
credentials.apiAdaptor.createAutoscaler(namespace, ((HorizontalPodAutoscalerBuilder) KubernetesApiConverter.toAutoscaler(new HorizontalPodAutoscalerBuilder(), description, name, kind)).build())
credentials.apiAdaptor.createAutoscaler(namespace, ((HorizontalPodAutoscalerBuilder) KubernetesApiConverter.toAutoscaler(new HorizontalPodAutoscalerBuilder(), description, name, kind, version)).build())
}

return null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ class DeployKubernetesAtomicOperation implements AtomicOperation<DeploymentResul
}

replicaSet = credentials.apiAdaptor.createReplicaSet(namespace, replicaSet)

task.updateStatus BASE_PHASE, "Deployed replica set ${replicaSet.metadata.name}"

if (hasDeployment) {
Expand All @@ -162,7 +161,8 @@ class DeployKubernetesAtomicOperation implements AtomicOperation<DeploymentResul

def name = hasDeployment ? clusterName : replicaSetName
def kind = hasDeployment ? KubernetesUtil.DEPLOYMENT_KIND : KubernetesUtil.SERVER_GROUP_KIND
def autoscaler = ((HorizontalPodAutoscalerBuilder) KubernetesApiConverter.toAutoscaler(new HorizontalPodAutoscalerBuilder(), new KubernetesAutoscalerDescription(replicaSetName, description), name, kind)).build()
def version = hasDeployment ? credentials.apiAdaptor.getDeployment(namespace, clusterName).getApiVersion() : replicaSet.getApiVersion()
def autoscaler = ((HorizontalPodAutoscalerBuilder) KubernetesApiConverter.toAutoscaler(new HorizontalPodAutoscalerBuilder(), new KubernetesAutoscalerDescription(replicaSetName, description), name, kind, version)).build()

if (credentials.apiAdaptor.getAutoscaler(namespace, name)) {
credentials.apiAdaptor.deleteAutoscaler(namespace, name)
Expand Down

0 comments on commit 3eac933

Please sign in to comment.