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
6 changes: 6 additions & 0 deletions api/src/main/java/org/apache/cloudstack/api/ApiConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public class ApiConstants {
public static final String COMBINED_CAPACITY_ORDERING = "COMBINED";
public static final String CONTROLLER = "controller";
public static final String CONTROLLER_UNIT = "controllerunit";
public static final String CONTROLLER_MANAGER_ARGS = "controllermanagerargs";
public static final String CONSOLE_ENDPOINT_CREATOR_ADDRESS = "consoleendpointcreatoraddress";
public static final String COPY_IMAGE_TAGS = "copyimagetags";
public static final String CPU_OVERCOMMIT_RATIO = "cpuOvercommitRatio";
Expand Down Expand Up @@ -155,6 +156,8 @@ public class ApiConstants {
public static final String CN = "cn";
public static final String COMMAND = "command";
public static final String CMD_EVENT_TYPE = "cmdeventtype";
public static final String API_SERVER_ARGS = "apiserverargs";
public static final String AUDIT_POLICY = "auditpolicy";
public static final String CNI_CONFIG = "cniconfig";
public static final String CNI_CONFIG_ID = "cniconfigurationid";
public static final String CNI_CONFIG_DETAILS = "cniconfigdetails";
Expand Down Expand Up @@ -185,6 +188,7 @@ public class ApiConstants {
public static final String ENCRYPT_FORMAT = "encryptformat";
public static final String ENCRYPT_ROOT = "encryptroot";
public static final String ENCRYPTION_SUPPORTED = "encryptionsupported";
public static final String ETCD_ARGS = "etcdargs";
public static final String ETCD_IPS = "etcdips";
public static final String MIN_IOPS = "miniops";
public static final String MAX_IOPS = "maxiops";
Expand Down Expand Up @@ -450,6 +454,7 @@ public class ApiConstants {
public static final String NEW_START_IP = "newstartip";
public static final String NEW_END_IP = "newendip";
public static final String KUBERNETES_NODE_VERSION = "kubernetesnodeversion";
public static final String KUBELET_CONFIG = "kubeletconfig";
public static final String NUMA_NODE = "numanode";
public static final String NUM_RETRIES = "numretries";
public static final String OFFER_HA = "offerha";
Expand Down Expand Up @@ -563,6 +568,7 @@ public class ApiConstants {
public static final String QUICK_RESTORE = "quickrestore";
public static final String SCHEDULE = "schedule";
public static final String SCHEDULE_ID = "scheduleid";
public static final String SCHEDULER_ARGS = "schedulerargs";
public static final String SCOPE = "scope";
public static final String SEARCH_BASE = "searchbase";
public static final String SECONDARY_IP = "secondaryip";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@
import com.cloud.kubernetes.cluster.dao.KubernetesClusterDao;
import com.cloud.kubernetes.cluster.dao.KubernetesClusterDetailsDao;
import com.cloud.kubernetes.cluster.dao.KubernetesClusterVmMapDao;
import com.cloud.kubernetes.cluster.utils.KubeadmConfigBuilder;
import com.cloud.kubernetes.version.KubernetesSupportedVersion;
import com.cloud.kubernetes.version.KubernetesSupportedVersionVO;
import com.cloud.kubernetes.version.KubernetesVersionManagerImpl;
Expand Down Expand Up @@ -298,6 +299,8 @@ public class KubernetesClusterManagerImpl extends ManagerBase implements Kuberne
ListKubernetesClustersCmd.class,
ScaleKubernetesClusterCmd.class
);
private static final String NODE_SETTINGS_PARAMETERS = String.join(", ", ApiConstants.API_SERVER_ARGS, ApiConstants.ETCD_ARGS,
ApiConstants.CONTROLLER_MANAGER_ARGS, ApiConstants.SCHEDULER_ARGS, ApiConstants.KUBELET_CONFIG, ApiConstants.AUDIT_POLICY);
private static final String PROJECT_KUBERNETES_ACCOUNT_FIRST_NAME = "Kubernetes";
private static final String PROJECT_KUBERNETES_ACCOUNT_LAST_NAME = "Service User";
private static final String DEFAULT_NETWORK_OFFERING_FOR_KUBERNETES_SERVICE_DISPLAY_TEXT = "Network Offering used for CloudStack Kubernetes service";
Expand Down Expand Up @@ -962,11 +965,28 @@ public KubernetesClusterResponse createKubernetesClusterResponse(long kubernetes
response.setClusterType(kubernetesCluster.getClusterType());
response.setCsiEnabled(kubernetesCluster.isCsiEnabled());
response.setCreated(kubernetesCluster.getCreated());
setNodeSettingsResponse(response, kubernetesCluster.getId());
setNodeTypeAffinityGroupResponse(response, kubernetesCluster.getId());

return response;
}

protected void setNodeSettingsResponse(KubernetesClusterResponse response, long clusterId) {
Map<String, String> details = kubernetesClusterDetailsDao.listDetailsKeyPairs(clusterId, List.of(ApiConstants.API_SERVER_ARGS,
ApiConstants.ETCD_ARGS, ApiConstants.CONTROLLER_MANAGER_ARGS, ApiConstants.SCHEDULER_ARGS, ApiConstants.KUBELET_CONFIG, ApiConstants.AUDIT_POLICY));
response.setApiServerArgs(argsDetail(details, ApiConstants.API_SERVER_ARGS));
response.setEtcdArgs(argsDetail(details, ApiConstants.ETCD_ARGS));
response.setControllerManagerArgs(argsDetail(details, ApiConstants.CONTROLLER_MANAGER_ARGS));
response.setSchedulerArgs(argsDetail(details, ApiConstants.SCHEDULER_ARGS));
response.setKubeletConfig(details.get(ApiConstants.KUBELET_CONFIG));
response.setAuditPolicy(details.get(ApiConstants.AUDIT_POLICY));
}

private Map<String, String> argsDetail(Map<String, String> details, String name) {
String args = details.get(name);
return StringUtils.isEmpty(args) ? null : KubeadmConfigBuilder.argsFromJson(args);
}

protected void setNodeTypeAffinityGroupResponse(KubernetesClusterResponse response, long clusterId) {
setAffinityGroupResponseForNodeType(response, clusterId, CONTROL.name());
setAffinityGroupResponseForNodeType(response, clusterId, WORKER.name());
Expand Down Expand Up @@ -1065,6 +1085,34 @@ private void validateUnmanagedKubernetesClusterCreateParameters(final CreateKube
if (StringUtils.isNotEmpty(externalLoadBalancerIpAddress) && (!NetUtils.isValidIp4(externalLoadBalancerIpAddress) && !NetUtils.isValidIp6(externalLoadBalancerIpAddress))) {
throw new InvalidParameterValueException("Invalid external load balancer IP address");
}

if (hasNodeSettings(cmd)) {
throw new InvalidParameterValueException(String.format("%s are not supported for %s clusters",
NODE_SETTINGS_PARAMETERS, KubernetesCluster.ClusterType.ExternalManaged));
}
}

private boolean hasNodeSettings(final CreateKubernetesClusterCmd cmd) {
return !cmd.getComponentArgs().isEmpty() || StringUtils.isNotBlank(cmd.getKubeletConfig()) || StringUtils.isNotEmpty(cmd.getAuditPolicy());
}

protected void validateNodeSettings(final CreateKubernetesClusterCmd cmd, final KubernetesSupportedVersion clusterKubernetesVersion) {
if (!hasNodeSettings(cmd)) {
return;
}
cmd.getComponentArgs().forEach(KubeadmConfigBuilder::validateArgs);
KubeadmConfigBuilder.normalizeKubeletConfig(cmd.getKubeletConfig());
KubeadmConfigBuilder.validateAuditPolicy(cmd.getAuditPolicy());
boolean supported;
try {
supported = KubernetesVersionManagerImpl.compareSemanticVersions(clusterKubernetesVersion.getSemanticVersion(), KubeadmConfigBuilder.MIN_KUBERNETES_VERSION) >= 0;
} catch (IllegalArgumentException e) {
supported = false;
}
if (!supported) {
throw new InvalidParameterValueException(String.format("%s need Kubernetes version %s or above",
NODE_SETTINGS_PARAMETERS, KubeadmConfigBuilder.MIN_KUBERNETES_VERSION));
}
}

public boolean isCommandSupported(KubernetesCluster cluster, String cmdName) {
Expand Down Expand Up @@ -1178,6 +1226,8 @@ private void validateManagedKubernetesClusterCreateParameters(final CreateKubern

validateDockerRegistryParams(dockerRegistryUserName, dockerRegistryPassword, dockerRegistryUrl);

validateNodeSettings(cmd, clusterKubernetesVersion);

Network network = validateAndGetNetworkForKubernetesCreateParameters(networkId);

if (StringUtils.isNotEmpty(externalLoadBalancerIpAddress)) {
Expand Down Expand Up @@ -1305,6 +1355,9 @@ private void addKubernetesClusterDetails(final KubernetesCluster kubernetesClust
final String dockerRegistryPassword = cmd.getDockerRegistryPassword();
final String dockerRegistryUrl = cmd.getDockerRegistryUrl();
final boolean networkCleanup = cmd.getNetworkId() == null;
final Map<KubeadmConfigBuilder.Component, Map<String, String>> componentArgs = cmd.getComponentArgs();
final String kubeletConfig = KubeadmConfigBuilder.normalizeKubeletConfig(cmd.getKubeletConfig());
final String auditPolicy = cmd.getAuditPolicy();
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
Expand All @@ -1318,6 +1371,10 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
addKubernetesClusterDetailIfIsNotEmpty(details, kubernetesClusterId, ApiConstants.DOCKER_REGISTRY_USER_NAME, dockerRegistryUserName, true);
addKubernetesClusterDetailIfIsNotEmpty(details, kubernetesClusterId, ApiConstants.DOCKER_REGISTRY_PASSWORD, dockerRegistryPassword, false);
addKubernetesClusterDetailIfIsNotEmpty(details, kubernetesClusterId, ApiConstants.DOCKER_REGISTRY_URL, dockerRegistryUrl, true);
componentArgs.forEach((component, args) ->
details.add(new KubernetesClusterDetailsVO(kubernetesClusterId, component.getParameter(), KubeadmConfigBuilder.argsToJson(args), true)));
addKubernetesClusterDetailIfIsNotEmpty(details, kubernetesClusterId, ApiConstants.KUBELET_CONFIG, kubeletConfig, true);
addKubernetesClusterDetailIfIsNotEmpty(details, kubernetesClusterId, ApiConstants.AUDIT_POLICY, auditPolicy, true);
if (kubernetesCluster.getClusterType() == KubernetesCluster.ClusterType.CloudManaged) {
details.add(new KubernetesClusterDetailsVO(kubernetesClusterId, "networkCleanup", String.valueOf(networkCleanup), true));
}
Expand Down
Loading
Loading