Skip to content
Merged
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 @@ -95,6 +95,7 @@ public class VMTemplateDaoImpl extends GenericDaoBase<VMTemplateVO, Long> implem

protected SearchBuilder<VMTemplateVO> AccountIdSearch;
protected SearchBuilder<VMTemplateVO> NameSearch;
protected SearchBuilder<VMTemplateVO> ValidNameSearch;
protected SearchBuilder<VMTemplateVO> TmpltsInZoneSearch;
protected SearchBuilder<VMTemplateVO> ActiveTmpltSearch;
private SearchBuilder<VMTemplateVO> PublicSearch;
Expand Down Expand Up @@ -138,8 +139,9 @@ public VMTemplateVO findByTemplateName(String templateName) {

@Override
public VMTemplateVO findValidByTemplateName(String templateName) {
SearchCriteria<VMTemplateVO> sc = NameSearch.create();
SearchCriteria<VMTemplateVO> sc = ValidNameSearch.create();
sc.setParameters("name", templateName);
sc.setParameters("state", VirtualMachineTemplate.State.Active);
return findOneBy(sc);
}

Expand Down Expand Up @@ -319,6 +321,10 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
UniqueNameSearch.and("uniqueName", UniqueNameSearch.entity().getUniqueName(), SearchCriteria.Op.EQ);
NameSearch = createSearchBuilder();
NameSearch.and("name", NameSearch.entity().getName(), SearchCriteria.Op.EQ);
ValidNameSearch = createSearchBuilder();
ValidNameSearch.and("name", ValidNameSearch.entity().getName(), SearchCriteria.Op.EQ);
ValidNameSearch.and("state", ValidNameSearch.entity().getState(), SearchCriteria.Op.EQ);
ValidNameSearch.and("removed", ValidNameSearch.entity().getRemoved(), SearchCriteria.Op.NULL);

NameAccountIdSearch = createSearchBuilder();
NameAccountIdSearch.and("name", NameAccountIdSearch.entity().getName(), SearchCriteria.Op.EQ);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ private boolean isKubernetesServiceTemplateConfigured(DataCenter zone) {
LOGGER.warn(String.format("Global setting %s is empty. Template name need to be specified for Kubernetes service to function", templateKey));
return false;
}
final VMTemplateVO template = templateDao.findByTemplateName(templateName);
final VMTemplateVO template = templateDao.findValidByTemplateName(templateName);
if (template == null) {
LOGGER.warn(String.format("Unable to find the template %s to be used for provisioning Kubernetes cluster nodes", templateName));
return false;
Expand Down Expand Up @@ -375,22 +375,22 @@ private IpAddress getSourceNatIp(Network network) {
}

private VMTemplateVO getKubernetesServiceTemplate(Hypervisor.HypervisorType hypervisorType) {
String tempalteName = null;
String templateName = null;
switch (hypervisorType) {
case Hyperv:
tempalteName = KubernetesClusterHyperVTemplateName.value();
templateName = KubernetesClusterHyperVTemplateName.value();
break;
case KVM:
tempalteName = KubernetesClusterKVMTemplateName.value();
templateName = KubernetesClusterKVMTemplateName.value();
break;
case VMware:
tempalteName = KubernetesClusterVMwareTemplateName.value();
templateName = KubernetesClusterVMwareTemplateName.value();
break;
case XenServer:
tempalteName = KubernetesClusterXenserverTemplateName.value();
templateName = KubernetesClusterXenserverTemplateName.value();
break;
}
return templateDao.findValidByTemplateName(tempalteName);
return templateDao.findValidByTemplateName(templateName);
}

private boolean validateIsolatedNetwork(Network network, int clusterTotalNodeCount) {
Expand Down Expand Up @@ -514,7 +514,7 @@ private DeployDestination plan(final long nodesCount, final DataCenter zone, fin
}
boolean suitable_host_found = false;
Cluster planCluster = null;
for (int i = 1; i <= nodesCount + 1; i++) {
for (int i = 1; i <= nodesCount; i++) {
suitable_host_found = false;
for (Map.Entry<String, Pair<HostVO, Integer>> hostEntry : hosts_with_resevered_capacity.entrySet()) {
Pair<HostVO, Integer> hp = hostEntry.getValue();
Expand Down Expand Up @@ -991,7 +991,7 @@ public KubernetesCluster createKubernetesCluster(CreateKubernetesClusterCmd cmd)
try {
deployDestination = plan(totalNodeCount, zone, serviceOffering);
} catch (InsufficientCapacityException e) {
logAndThrow(Level.ERROR, String.format("Creating Kubernetes cluster failed due to insufficient capacity for %d cluster nodes in zone ID: %s with service offering ID: %s", totalNodeCount, zone.getUuid(), serviceOffering.getUuid()));
logAndThrow(Level.ERROR, String.format("Creating Kubernetes cluster failed due to insufficient capacity for %d nodes cluster in zone ID: %s with service offering ID: %s", totalNodeCount, zone.getUuid(), serviceOffering.getUuid()));
}
if (deployDestination == null || deployDestination.getCluster() == null) {
logAndThrow(Level.ERROR, String.format("Creating Kubernetes cluster failed due to error while finding suitable deployment plan for cluster in zone ID: %s", zone.getUuid()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,24 +198,25 @@ public boolean destroy() throws CloudRuntimeException {
}
if (cleanupNetwork) { // if network has additional VM, cannot proceed with cluster destroy
NetworkVO network = networkDao.findById(kubernetesCluster.getNetworkId());
if (network == null) {
logAndThrow(Level.ERROR, String.format("Failed to find network for Kubernetes cluster ID: %s", kubernetesCluster.getUuid()));
}
List<VMInstanceVO> networkVMs = vmInstanceDao.listNonRemovedVmsByTypeAndNetwork(network.getId(), VirtualMachine.Type.User);
if (networkVMs.size() > clusterVMs.size()) {
logAndThrow(Level.ERROR, String.format("Network ID: %s for Kubernetes cluster ID: %s has instances using it which are not part of the Kubernetes cluster", network.getUuid(), kubernetesCluster.getUuid()));
}
for (VMInstanceVO vm : networkVMs) {
boolean vmFoundInKubernetesCluster = false;
for (KubernetesClusterVmMap clusterVM : clusterVMs) {
if (vm.getId() == clusterVM.getVmId()) {
vmFoundInKubernetesCluster = true;
break;
}
if (network != null) {
List<VMInstanceVO> networkVMs = vmInstanceDao.listNonRemovedVmsByTypeAndNetwork(network.getId(), VirtualMachine.Type.User);
if (networkVMs.size() > clusterVMs.size()) {
logAndThrow(Level.ERROR, String.format("Network ID: %s for Kubernetes cluster ID: %s has instances using it which are not part of the Kubernetes cluster", network.getUuid(), kubernetesCluster.getUuid()));
}
if (!vmFoundInKubernetesCluster) {
logAndThrow(Level.ERROR, String.format("VM ID: %s which is not a part of Kubernetes cluster ID: %s is using Kubernetes cluster network ID: %s", vm.getUuid(), kubernetesCluster.getUuid(), network.getUuid()));
for (VMInstanceVO vm : networkVMs) {
boolean vmFoundInKubernetesCluster = false;
for (KubernetesClusterVmMap clusterVM : clusterVMs) {
if (vm.getId() == clusterVM.getVmId()) {
vmFoundInKubernetesCluster = true;
break;
}
}
if (!vmFoundInKubernetesCluster) {
logAndThrow(Level.ERROR, String.format("VM ID: %s which is not a part of Kubernetes cluster ID: %s is using Kubernetes cluster network ID: %s", vm.getUuid(), kubernetesCluster.getUuid(), network.getUuid()));
}
}
} else {
LOGGER.error(String.format("Failed to find network for Kubernetes cluster ID: %s", kubernetesCluster.getUuid()));
}
}
if (LOGGER.isInfoEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ protected DeployDestination plan(final long nodesCount, final DataCenter zone, f
hosts_with_resevered_capacity.put(h.getUuid(), new Pair<HostVO, Integer>(h, 0));
}
boolean suitable_host_found = false;
for (int i = 1; i <= nodesCount + 1; i++) {
for (int i = 1; i <= nodesCount; i++) {
suitable_host_found = false;
for (Map.Entry<String, Pair<HostVO, Integer>> hostEntry : hosts_with_resevered_capacity.entrySet()) {
Pair<HostVO, Integer> hp = hostEntry.getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,19 @@

public class KubernetesClusterStartWorker extends KubernetesClusterResourceModifierActionWorker {

private KubernetesSupportedVersion kubernetesClusterVersion;

public KubernetesClusterStartWorker(final KubernetesCluster kubernetesCluster, final KubernetesClusterManagerImpl clusterManager) {
super(kubernetesCluster, clusterManager);
}

public KubernetesSupportedVersion getKubernetesClusterVersion() {
if (kubernetesClusterVersion == null) {
kubernetesClusterVersion = kubernetesSupportedVersionDao.findById(kubernetesCluster.getKubernetesVersionId());
}
return kubernetesClusterVersion;
}

private Pair<String, Map<Long, Network.IpAddresses>> getKubernetesMasterIpAddresses(final DataCenter zone, final Network network, final Account account) throws InsufficientAddressCapacityException {
String masterIp = null;
Map<Long, Network.IpAddresses> requestedIps = null;
Expand All @@ -105,7 +114,7 @@ private Pair<String, Map<Long, Network.IpAddresses>> getKubernetesMasterIpAddres

private boolean isKubernetesVersionSupportsHA() {
boolean haSupported = false;
final KubernetesSupportedVersion version = kubernetesSupportedVersionDao.findById(kubernetesCluster.getKubernetesVersionId());
KubernetesSupportedVersion version = getKubernetesClusterVersion();
if (version != null) {
try {
if (KubernetesVersionManagerImpl.compareSemanticVersions(version.getSemanticVersion(), KubernetesClusterService.MIN_KUBERNETES_VERSION_HA_SUPPORT) >= 0) {
Expand Down Expand Up @@ -161,6 +170,7 @@ private String getKubernetesMasterConfig(final String masterIp, final String ser
KubernetesClusterUtil.generateClusterHACertificateKey(kubernetesCluster));
}
initArgs += String.format("--apiserver-cert-extra-sans=%s", serverIp);
initArgs += String.format(" --kubernetes-version=%s", getKubernetesClusterVersion().getSemanticVersion());
k8sMasterConfig = k8sMasterConfig.replace(clusterInitArgsKey, initArgs);
k8sMasterConfig = k8sMasterConfig.replace(ejectIsoKey, String.valueOf(ejectIso));
return k8sMasterConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ public static int compareSemanticVersions(String v1, String v2) throws IllegalAr
throw new IllegalArgumentException(String.format("Invalid version comparision with versions %s, %s", v1, v2));
}
if(!isSemanticVersion(v1)) {
throw new IllegalArgumentException(String.format("Invalid version format, %s", v1));
throw new IllegalArgumentException(String.format("Invalid version format, %s. Semantic version should be specified in MAJOR.MINOR.PATCH format", v1));
}
if(!isSemanticVersion(v2)) {
throw new IllegalArgumentException(String.format("Invalid version format, %s", v2));
throw new IllegalArgumentException(String.format("Invalid version format, %s. Semantic version should be specified in MAJOR.MINOR.PATCH format", v2));
}
String[] thisParts = v1.split("\\.");
String[] thatParts = v2.split("\\.");
Expand Down Expand Up @@ -287,10 +287,10 @@ public KubernetesSupportedVersionResponse addKubernetesSupportedVersion(final Ad
final Integer minimumCpu = cmd.getMinimumCpu();
final Integer minimumRamSize = cmd.getMinimumRamSize();
if (minimumCpu == null || minimumCpu < KubernetesClusterService.MIN_KUBERNETES_CLUSTER_NODE_CPU) {
throw new InvalidParameterValueException(String.format("Invalid value for %s parameter", ApiConstants.MIN_CPU_NUMBER));
throw new InvalidParameterValueException(String.format("Invalid value for %s parameter. Minimum %d vCPUs required.", ApiConstants.MIN_CPU_NUMBER, KubernetesClusterService.MIN_KUBERNETES_CLUSTER_NODE_CPU));
}
if (minimumRamSize == null || minimumRamSize < KubernetesClusterService.MIN_KUBERNETES_CLUSTER_NODE_RAM_SIZE) {
throw new InvalidParameterValueException(String.format("Invalid value for %s parameter", ApiConstants.MIN_MEMORY));
throw new InvalidParameterValueException(String.format("Invalid value for %s parameter. Minimum %dMB memory required", ApiConstants.MIN_MEMORY, KubernetesClusterService.MIN_KUBERNETES_CLUSTER_NODE_RAM_SIZE));
}
if (compareSemanticVersions(semanticVersion, MIN_KUBERNETES_VERSION) < 0) {
throw new InvalidParameterValueException(String.format("New supported Kubernetes version cannot be added as %s is minimum version supported by Kubernetes Service", MIN_KUBERNETES_VERSION));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class AddKubernetesSupportedVersionCmd extends BaseCmd implements AdminCm
private String name;

@Parameter(name = ApiConstants.SEMANTIC_VERSION, type = CommandType.STRING, required = true,
description = "the semantic version of the Kubernetes version")
description = "the semantic version of the Kubernetes version. It needs to be specified in MAJOR.MINOR.PATCH format")
private String semanticVersion;

@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.UUID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,14 @@ public String getEventType() {

@Override
public String getEventDescription() {
return "Deleting Kubernetes supported version " + getId();
String description = "Deleting Kubernetes supported version";
KubernetesSupportedVersion version = _entityMgr.findById(KubernetesSupportedVersion.class, getId());
if (version != null) {
description += String.format(" ID: %s", version.getUuid());
} else {
description += String.format(" ID: %d", getId());
}
return description;
}

/////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public String getCreateEventDescription() {

@Override
public String getEventDescription() {
return "creating Kubernetes cluster. Cluster Id: " + getEntityId();
return "Creating Kubernetes cluster. Cluster Id: " + getEntityId();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,14 @@ public String getEventType() {

@Override
public String getEventDescription() {
String description = "Deleting Kubernetes cluster";
KubernetesCluster cluster = _entityMgr.findById(KubernetesCluster.class, getId());
return String.format("Deleting Kubernetes cluster ID: %s", cluster.getUuid());
if (cluster != null) {
description += String.format(" ID: %s", cluster.getUuid());
} else {
description += String.format(" ID: %d", getId());
}
return description;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,14 @@ public String getEventType() {

@Override
public String getEventDescription() {
String description = "Scaling Kubernetes cluster";
KubernetesCluster cluster = _entityMgr.findById(KubernetesCluster.class, getId());
return String.format("Scaling Kubernetes cluster ID: %s", cluster.getUuid());
if (cluster != null) {
description += String.format(" ID: %s", cluster.getUuid());
} else {
description += String.format(" ID: %d", getId());
}
return description;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,14 @@ public String getEventType() {

@Override
public String getEventDescription() {
String description = "Starting Kubernetes cluster";
KubernetesCluster cluster = _entityMgr.findById(KubernetesCluster.class, getId());
return String.format("Starting Kubernetes cluster ID: %s", cluster.getUuid());
if (cluster != null) {
description += String.format(" ID: %s", cluster.getUuid());
} else {
description += String.format(" ID: %d", getId());
}
return description;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,14 @@ public String getEventType() {

@Override
public String getEventDescription() {
String description = "Stopping Kubernetes cluster";
KubernetesCluster cluster = _entityMgr.findById(KubernetesCluster.class, getId());
return String.format("Stopping Kubernetes cluster ID: %s", cluster.getUuid());
if (cluster != null) {
description += String.format(" ID: %s", cluster.getUuid());
} else {
description += String.format(" ID: %d", getId());
}
return description;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,14 @@ public String getEventType() {

@Override
public String getEventDescription() {
String description = "Upgrading Kubernetes cluster";
KubernetesCluster cluster = _entityMgr.findById(KubernetesCluster.class, getId());
return String.format("Upgrading Kubernetes cluster ID: %s", cluster.getUuid());
if (cluster != null) {
description += String.format(" ID: %s", cluster.getUuid());
} else {
description += String.format(" ID: %d", getId());
}
return description;
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion scripts/util/create-kubernetes-binaries-iso.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ if [ $? -ne 0 ]; then
fi
fi
mkdir -p "${working_dir}/docker"
output=`${k8s_dir}/kubeadm config images list`
output=`${k8s_dir}/kubeadm config images list --kubernetes-version=${RELEASE}`
while read -r line; do
echo "Downloading docker image $line ---"
sudo docker pull "$line"
Expand Down
Loading