All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.alauda.kubernetes.client.dsl.internal.ReplicationControllerRollingUpdater Maven / Gradle / Ivy

There is a newer version: 0.2.8
Show newest version
/**
 * Copyright (C) 2018 Alauda
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.alauda.kubernetes.client.dsl.internal;

import io.alauda.kubernetes.client.dsl.Operation;
import okhttp3.OkHttpClient;
import io.alauda.kubernetes.api.model.DoneableReplicationController;
import io.alauda.kubernetes.api.model.PodList;
import io.alauda.kubernetes.api.model.ReplicationController;
import io.alauda.kubernetes.api.model.ReplicationControllerBuilder;
import io.alauda.kubernetes.api.model.ReplicationControllerList;
import io.alauda.kubernetes.client.Config;
import io.alauda.kubernetes.client.dsl.RollableScalableResource;

class ReplicationControllerRollingUpdater extends RollingUpdater {

  ReplicationControllerRollingUpdater(OkHttpClient client, Config config, String namespace) {
    super(client, config, namespace);
  }

  ReplicationControllerRollingUpdater(OkHttpClient client, Config config, String namespace, long rollingTimeoutMillis, long loggingIntervalMillis) {
    super(client, config, namespace, rollingTimeoutMillis, loggingIntervalMillis);
  }

  @Override
  protected ReplicationController createClone(ReplicationController obj, String newName, String newDeploymentHash) {
    return new ReplicationControllerBuilder(obj)
      .editMetadata()
      .withResourceVersion(null)
      .withName(newName)
      .endMetadata()
      .editSpec()
      .withReplicas(0).addToSelector(DEPLOYMENT_KEY, newDeploymentHash)
      .editTemplate().editMetadata().addToLabels(DEPLOYMENT_KEY, newDeploymentHash).endMetadata().endTemplate()
      .endSpec()
      .build();
  }

  @Override
  protected PodList listSelectedPods(ReplicationController obj) {
    return pods().inNamespace(namespace).withLabels(obj.getSpec().getSelector()).list();
  }

  @Override
  protected void updateDeploymentKey(DoneableReplicationController obj, String hash) {
    obj.editSpec()
      .addToSelector(DEPLOYMENT_KEY, hash)
      .editTemplate().editMetadata().addToLabels(DEPLOYMENT_KEY, hash).endMetadata().endTemplate()
      .endSpec();
  }

  @Override
  protected void removeDeploymentKey(DoneableReplicationController obj) {
    obj.editSpec()
      .removeFromSelector(DEPLOYMENT_KEY)
      .editTemplate().editMetadata().removeFromLabels(DEPLOYMENT_KEY).endMetadata().endTemplate()
      .endSpec();
  }

  @Override
  protected int getReplicas(ReplicationController obj) {
    return obj.getSpec().getReplicas();
  }

  @Override
  protected ReplicationController setReplicas(ReplicationController obj, int replicas) {
    return new ReplicationControllerBuilder(obj).editSpec().withReplicas(replicas).endSpec().build();
  }

  @Override
  protected Operation> resources() {
    return new ReplicationControllerOperationsImpl(client, config, namespace);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy