-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(kubernetes): support rolling restart operation for deployments
- Loading branch information
1 parent
079ee0a
commit e076eba
Showing
11 changed files
with
276 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...ouddriver/kubernetes/v2/converter/manifest/KubernetesRollingRestartManifestConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2019 Google, Inc. | ||
* | ||
* 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 com.netflix.spinnaker.clouddriver.kubernetes.v2.converter.manifest; | ||
|
||
import static com.netflix.spinnaker.clouddriver.orchestration.AtomicOperations.ROLLING_RESTART_MANIFEST; | ||
|
||
import com.netflix.spinnaker.clouddriver.kubernetes.KubernetesOperation; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.deploy.converters.KubernetesAtomicOperationConverterHelper; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesRollingRestartManifestDescription; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.v2.op.manifest.KubernetesRollingRestartManifestOperation; | ||
import com.netflix.spinnaker.clouddriver.orchestration.AtomicOperation; | ||
import com.netflix.spinnaker.clouddriver.security.AbstractAtomicOperationsCredentialsSupport; | ||
import com.netflix.spinnaker.clouddriver.security.ProviderVersion; | ||
import java.util.Map; | ||
import org.springframework.stereotype.Component; | ||
|
||
@KubernetesOperation(ROLLING_RESTART_MANIFEST) | ||
@Component | ||
public class KubernetesRollingRestartManifestConverter | ||
extends AbstractAtomicOperationsCredentialsSupport { | ||
@Override | ||
public AtomicOperation convertOperation(Map input) { | ||
return new KubernetesRollingRestartManifestOperation(convertDescription(input)); | ||
} | ||
|
||
@Override | ||
public KubernetesRollingRestartManifestDescription convertDescription(Map input) { | ||
return KubernetesAtomicOperationConverterHelper.convertDescription( | ||
input, this, KubernetesRollingRestartManifestDescription.class); | ||
} | ||
|
||
@Override | ||
public boolean acceptsVersion(ProviderVersion version) { | ||
return version == ProviderVersion.v2; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...river/kubernetes/v2/description/manifest/KubernetesRollingRestartManifestDescription.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright 2019 Google, Inc. | ||
* | ||
* 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 com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest; | ||
|
||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
|
||
@EqualsAndHashCode(callSuper = true) | ||
@Data | ||
public class KubernetesRollingRestartManifestDescription | ||
extends KubernetesManifestOperationDescription {} |
28 changes: 28 additions & 0 deletions
28
...in/java/com/netflix/spinnaker/clouddriver/kubernetes/v2/op/handler/CanRollingRestart.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2019 Google, Inc. | ||
* | ||
* 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 com.netflix.spinnaker.clouddriver.kubernetes.v2.op.handler; | ||
|
||
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesKind; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.v2.security.KubernetesV2Credentials; | ||
|
||
public interface CanRollingRestart { | ||
KubernetesKind kind(); | ||
|
||
default void rollingRestart(KubernetesV2Credentials credentials, String namespace, String name) { | ||
credentials.rollingRestart(kind(), namespace, name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...aker/clouddriver/kubernetes/v2/op/manifest/KubernetesRollingRestartManifestOperation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2019 Google, Inc. | ||
* | ||
* 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 com.netflix.spinnaker.clouddriver.kubernetes.v2.op.manifest; | ||
|
||
import com.netflix.spinnaker.clouddriver.data.task.Task; | ||
import com.netflix.spinnaker.clouddriver.data.task.TaskRepository; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.KubernetesCoordinates; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.KubernetesResourceProperties; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesRollingRestartManifestDescription; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.v2.op.handler.CanRollingRestart; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.v2.op.handler.KubernetesHandler; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.v2.security.KubernetesV2Credentials; | ||
import com.netflix.spinnaker.clouddriver.orchestration.AtomicOperation; | ||
import java.util.List; | ||
|
||
public class KubernetesRollingRestartManifestOperation implements AtomicOperation<Void> { | ||
private final KubernetesRollingRestartManifestDescription description; | ||
private final KubernetesV2Credentials credentials; | ||
private static final String OP_NAME = "ROLLING_RESTART_KUBERNETES_MANIFEST"; | ||
|
||
public KubernetesRollingRestartManifestOperation( | ||
KubernetesRollingRestartManifestDescription description) { | ||
this.description = description; | ||
this.credentials = (KubernetesV2Credentials) description.getCredentials().getCredentials(); | ||
} | ||
|
||
private static Task getTask() { | ||
return TaskRepository.threadLocalTask.get(); | ||
} | ||
|
||
@Override | ||
public Void operate(List priorOutputs) { | ||
getTask().updateStatus(OP_NAME, "Starting rolling restart operation..."); | ||
KubernetesCoordinates coordinates = description.getPointCoordinates(); | ||
|
||
getTask().updateStatus(OP_NAME, "Looking up resource properties..."); | ||
KubernetesResourceProperties properties = | ||
credentials.getResourcePropertyRegistry().get(coordinates.getKind()); | ||
KubernetesHandler deployer = properties.getHandler(); | ||
|
||
if (!(deployer instanceof CanRollingRestart)) { | ||
throw new IllegalArgumentException( | ||
"Resource with " + coordinates + " does not support rolling restart"); | ||
} | ||
|
||
CanRollingRestart canRollingRestart = (CanRollingRestart) deployer; | ||
|
||
getTask().updateStatus(OP_NAME, "Calling rolling restart operation..."); | ||
canRollingRestart.rollingRestart( | ||
credentials, coordinates.getNamespace(), coordinates.getName()); | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...ouddriver/kubernetes/v2/validator/manifest/KubernetesRollingRestartManifestValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright 2019 Google, Inc. | ||
* | ||
* 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 com.netflix.spinnaker.clouddriver.kubernetes.v2.validator.manifest; | ||
|
||
import static com.netflix.spinnaker.clouddriver.orchestration.AtomicOperations.ROLLING_RESTART_MANIFEST; | ||
|
||
import com.netflix.spinnaker.clouddriver.deploy.DescriptionValidator; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.KubernetesOperation; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.v2.description.manifest.KubernetesRollingRestartManifestDescription; | ||
import com.netflix.spinnaker.clouddriver.kubernetes.v2.validator.KubernetesValidationUtil; | ||
import com.netflix.spinnaker.clouddriver.security.AccountCredentialsProvider; | ||
import com.netflix.spinnaker.clouddriver.security.ProviderVersion; | ||
import java.util.List; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.validation.Errors; | ||
|
||
@KubernetesOperation(ROLLING_RESTART_MANIFEST) | ||
@Component | ||
public class KubernetesRollingRestartManifestValidator | ||
extends DescriptionValidator<KubernetesRollingRestartManifestDescription> { | ||
private final AccountCredentialsProvider provider; | ||
|
||
@Autowired | ||
public KubernetesRollingRestartManifestValidator(AccountCredentialsProvider provider) { | ||
this.provider = provider; | ||
} | ||
|
||
@Override | ||
public void validate( | ||
List priorDescriptions, | ||
KubernetesRollingRestartManifestDescription description, | ||
Errors errors) { | ||
KubernetesValidationUtil util = | ||
new KubernetesValidationUtil("rollingRestartKubernetesManifest", errors); | ||
if (!util.validateV2Credentials( | ||
provider, | ||
description.getAccount(), | ||
description.getPointCoordinates().getKind(), | ||
description.getPointCoordinates().getNamespace())) { | ||
return; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean acceptsVersion(ProviderVersion version) { | ||
return version == ProviderVersion.v2; | ||
} | ||
} |