Skip to content
Open
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 @@ -999,7 +999,10 @@ protected String updateKubeConfigWithRegistryDetails(String k8sConfig) {
}
}

if (StringUtils.isNoneEmpty(registryUsername, registryPassword, registryUrl)) {
final String registryEnabledKey = "{{ registry.enabled }}";
boolean registryEnabled = StringUtils.isNoneEmpty(registryUsername, registryPassword, registryUrl);
k8sConfig = k8sConfig.replace(registryEnabledKey, String.valueOf(registryEnabled));
if (registryEnabled) {
// Update runcmd in the cloud-init configuration to run a script that updates the containerd config with provided registry details
String runCmd = "- bash -x /opt/bin/setup-containerd";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ write_files:
sudo touch /home/cloud/success
echo "true" > /home/cloud/success

{% if registry is defined %}
Comment thread
Damans227 marked this conversation as resolved.
{% if "{{ registry.enabled }}" == "true" %}
- path: /opt/bin/setup-containerd
permissions: '0755'
owner: root:root
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// under the License.
package com.cloud.kubernetes.cluster.actionworkers;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -229,4 +230,28 @@ public void testGetMergedAffinityGroupIdsExplicitDedicationAlreadyInList() {
Assert.assertTrue(result.contains(99L));
Assert.assertTrue(result.contains(2L));
}

@Test
public void testUpdateKubeConfigWithRegistryDetailsControlNodeWritesSetupScript() throws IOException {
List<KubernetesClusterDetailsVO> details = Arrays.asList(
new KubernetesClusterDetailsVO(DEFAULT_ID, ApiConstants.DOCKER_REGISTRY_USER_NAME, "user", true),
new KubernetesClusterDetailsVO(DEFAULT_ID, ApiConstants.DOCKER_REGISTRY_PASSWORD, "pass", false),
new KubernetesClusterDetailsVO(DEFAULT_ID, ApiConstants.DOCKER_REGISTRY_URL, "https://index.docker.io/v1/", true));
Mockito.when(kubernetesClusterDetailsDao.listDetails(DEFAULT_ID)).thenReturn(details);
String config = actionWorker.updateKubeConfigWithRegistryDetails(actionWorker.readResourceFile("conf/k8s-control-node.yml"));
Assert.assertTrue(config.startsWith("## template: jinja"));
Assert.assertTrue(config.contains("{% if \"true\" == \"true\" %}"));
Assert.assertTrue(config.contains("- path: /opt/bin/setup-containerd"));
Assert.assertTrue(config.contains("- bash -x /opt/bin/setup-containerd"));
Assert.assertTrue(config.contains("registry.mirrors.\\\"index.docker.io/v1/\\\""));
}

@Test
public void testUpdateKubeConfigWithRegistryDetailsControlNodeNoRegistry() throws IOException {
Mockito.when(kubernetesClusterDetailsDao.listDetails(DEFAULT_ID)).thenReturn(new ArrayList<>());
String config = actionWorker.updateKubeConfigWithRegistryDetails(actionWorker.readResourceFile("conf/k8s-control-node.yml"));
Assert.assertTrue(config.contains("{% if \"false\" == \"true\" %}"));
Assert.assertFalse(config.contains("{{ registry.enabled }}"));
Assert.assertFalse(config.contains("- bash -x /opt/bin/setup-containerd"));
}
}
Loading