Skip to content

Commit e0a5df5

Browse files
authored
CKS Enhancements and SystemVM template upgrade improvements (apache#5863)
* This PR/commit comprises of the following: - Support to fallback on the older systemVM template in case of no change in template across ACS versions - Update core user to cloud in CKS - Display details of accessing CKS nodes in the UI - K8s Access tab - Update systemvm template from debian 11 to debian 11.2 - Update letsencrypt cert - Remove docker dependency as from ACS 4.16 onward k8s has deprecated support for docker - use containerd as container runtime * support for private registry - containerd * Enable updating template type (only) for system owned templates via UI * edit indents * Address comments and move cmd from patch file to cloud-init runcmd * temporary change * update k8s test to use k8s version 1.21.5 (instead of 1.21.3 - due to kubernetes/kubernetes#104530) * support for private registry - containerd * Enable updating template type (only) for system owned templates via UI * smooth upgrade of cks clusters * update pom file with temp download.cloudstack.org testing links * fix pom * add cgroup config for containerd * add systemd config for kubelet * add additional info during image registry config * update to official links
1 parent 8db598b commit e0a5df5

File tree

34 files changed

+521
-394
lines changed

34 files changed

+521
-394
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ tools/cli/cloudmonkey/precache.py
4848
tools/marvin/marvin/cloudstackAPI/
4949
tools/marvin/build/
5050
tools/cli/build/
51+
tools/appliance/systemvmtemplate/packer_cache/
5152
*.jar
5253
*.war
5354
*.mar

agent/src/main/java/com/cloud/agent/AgentShell.java

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,26 @@
1616
// under the License.
1717
package com.cloud.agent;
1818

19+
import com.cloud.agent.Agent.ExitStatus;
20+
import com.cloud.agent.dao.StorageComponent;
21+
import com.cloud.agent.dao.impl.PropertiesStorage;
22+
import com.cloud.resource.ServerResource;
23+
import com.cloud.utils.LogUtils;
24+
import com.cloud.utils.NumbersUtil;
25+
import com.cloud.utils.ProcessUtil;
26+
import com.cloud.utils.PropertiesUtil;
27+
import com.cloud.utils.backoff.BackoffAlgorithm;
28+
import com.cloud.utils.backoff.impl.ConstantTimeBackoff;
29+
import com.cloud.utils.exception.CloudRuntimeException;
30+
import com.google.common.base.Strings;
31+
import org.apache.commons.daemon.Daemon;
32+
import org.apache.commons.daemon.DaemonContext;
33+
import org.apache.commons.daemon.DaemonInitException;
34+
import org.apache.commons.lang.math.NumberUtils;
35+
import org.apache.log4j.Logger;
36+
import org.apache.log4j.xml.DOMConfigurator;
37+
38+
import javax.naming.ConfigurationException;
1939
import java.io.File;
2040
import java.io.FileNotFoundException;
2141
import java.io.IOException;
@@ -30,28 +50,6 @@
3050
import java.util.Properties;
3151
import java.util.UUID;
3252

33-
import javax.naming.ConfigurationException;
34-
35-
import org.apache.commons.daemon.Daemon;
36-
import org.apache.commons.daemon.DaemonContext;
37-
import org.apache.commons.daemon.DaemonInitException;
38-
import org.apache.commons.lang.math.NumberUtils;
39-
import org.apache.log4j.Logger;
40-
import org.apache.log4j.xml.DOMConfigurator;
41-
42-
import com.cloud.agent.Agent.ExitStatus;
43-
import com.cloud.agent.dao.StorageComponent;
44-
import com.cloud.agent.dao.impl.PropertiesStorage;
45-
import com.cloud.resource.ServerResource;
46-
import com.cloud.utils.LogUtils;
47-
import com.cloud.utils.NumbersUtil;
48-
import com.cloud.utils.ProcessUtil;
49-
import com.cloud.utils.PropertiesUtil;
50-
import com.cloud.utils.backoff.BackoffAlgorithm;
51-
import com.cloud.utils.backoff.impl.ConstantTimeBackoff;
52-
import com.cloud.utils.exception.CloudRuntimeException;
53-
import com.google.common.base.Strings;
54-
5553
public class AgentShell implements IAgentShell, Daemon {
5654
private static final Logger s_logger = Logger.getLogger(AgentShell.class.getName());
5755

@@ -423,13 +421,13 @@ private void launchAgentFromClassInfo(String resourceClassNames) throws Configur
423421
} catch (final ClassNotFoundException e) {
424422
throw new ConfigurationException("Resource class not found: " + name + " due to: " + e.toString());
425423
} catch (final SecurityException e) {
426-
throw new ConfigurationException("Security excetion when loading resource: " + name + " due to: " + e.toString());
424+
throw new ConfigurationException("Security exception when loading resource: " + name + " due to: " + e.toString());
427425
} catch (final NoSuchMethodException e) {
428-
throw new ConfigurationException("Method not found excetion when loading resource: " + name + " due to: " + e.toString());
426+
throw new ConfigurationException("Method not found exception when loading resource: " + name + " due to: " + e.toString());
429427
} catch (final IllegalArgumentException e) {
430-
throw new ConfigurationException("Illegal argument excetion when loading resource: " + name + " due to: " + e.toString());
428+
throw new ConfigurationException("Illegal argument exception when loading resource: " + name + " due to: " + e.toString());
431429
} catch (final InstantiationException e) {
432-
throw new ConfigurationException("Instantiation excetion when loading resource: " + name + " due to: " + e.toString());
430+
throw new ConfigurationException("Instantiation exception when loading resource: " + name + " due to: " + e.toString());
433431
} catch (final IllegalAccessException e) {
434432
throw new ConfigurationException("Illegal access exception when loading resource: " + name + " due to: " + e.toString());
435433
} catch (final InvocationTargetException e) {

api/src/main/java/com/cloud/vm/VmDetailConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,5 @@ public interface VmDetailConstants {
7373
String DISK_OFFERING = "diskOffering";
7474

7575
String DEPLOY_AS_IS_CONFIGURATION = "configurationId";
76+
String CKS_CONTROL_NODE_LOGIN_USER = "controlNodeLoginUser";
7677
}

engine/schema/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@
7373
</goals>
7474
<configuration>
7575
<source>
76-
def projectVersion = project.version
76+
def projectVersion = project.properties['project.systemvm.template.version']
7777
String[] versionParts = projectVersion.tokenize('.')
78-
pom.properties['cs.version'] = "4.16"
79-
pom.properties['patch.version'] = "0"
78+
pom.properties['cs.version'] = versionParts[0] + "." + versionParts[1]
79+
pom.properties['patch.version'] = versionParts[2]
8080
</source>
8181
</configuration>
8282
</execution>
@@ -146,7 +146,7 @@
146146
<executable>bash</executable>
147147
<arguments>
148148
<argument>templateConfig.sh</argument>
149-
<armument>${project.version}</armument>
149+
<argument>${project.systemvm.template.version}</argument>
150150
</arguments>
151151
</configuration>
152152
</execution>

engine/schema/src/main/java/com/cloud/upgrade/DatabaseUpgradeChecker.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,11 @@ public void check() {
367367
return;
368368
}
369369

370-
SystemVmTemplateRegistration.parseMetadataFile();
371-
final CloudStackVersion currentVersion = CloudStackVersion.parse(currentVersionValue);
372-
SystemVmTemplateRegistration.CS_MAJOR_VERSION = String.valueOf(currentVersion.getMajorRelease()) + "." + String.valueOf(currentVersion.getMinorRelease());
373-
SystemVmTemplateRegistration.CS_TINY_VERSION = String.valueOf(currentVersion.getPatchRelease());
370+
String csVersion = SystemVmTemplateRegistration.parseMetadataFile();
371+
final CloudStackVersion sysVmVersion = CloudStackVersion.parse(csVersion);
372+
final CloudStackVersion currentVersion = CloudStackVersion.parse(currentVersionValue);
373+
SystemVmTemplateRegistration.CS_MAJOR_VERSION = String.valueOf(sysVmVersion.getMajorRelease()) + "." + String.valueOf(sysVmVersion.getMinorRelease());
374+
SystemVmTemplateRegistration.CS_TINY_VERSION = String.valueOf(sysVmVersion.getPatchRelease());
374375

375376
s_logger.info("DB version = " + dbVersion + " Code Version = " + currentVersion);
376377

engine/schema/src/main/java/com/cloud/upgrade/SystemVmTemplateRegistration.java

Lines changed: 36 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
5555
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreDao;
5656
import org.apache.cloudstack.storage.datastore.db.TemplateDataStoreVO;
57-
import org.apache.commons.codec.digest.DigestUtils;
57+
import org.apache.cloudstack.utils.security.DigestHelper;
5858
import org.apache.commons.lang3.StringUtils;
5959
import org.apache.log4j.Logger;
6060
import org.ini4j.Ini;
@@ -64,7 +64,6 @@
6464
import java.io.File;
6565
import java.io.FileReader;
6666
import java.io.IOException;
67-
import java.io.InputStream;
6867
import java.net.URI;
6968
import java.nio.file.Files;
7069
import java.nio.file.Path;
@@ -351,16 +350,6 @@ public static boolean validateIfSeeded(String url, String path) {
351350
}
352351
}
353352

354-
private String calculateChecksum(File file) {
355-
try (InputStream is = Files.newInputStream(Paths.get(file.getPath()))) {
356-
return DigestUtils.md5Hex(is);
357-
} catch (IOException e) {
358-
String errMsg = "Failed to calculate template checksum";
359-
LOGGER.error(errMsg, e);
360-
throw new CloudRuntimeException(errMsg, e);
361-
}
362-
}
363-
364353
public Long getRegisteredTemplateId(Pair<Hypervisor.HypervisorType, String> hypervisorAndTemplateName) {
365354
VMTemplateVO vmTemplate = vmTemplateDao.findLatestTemplateByName(hypervisorAndTemplateName.second());
366355
Long templateId = null;
@@ -371,24 +360,24 @@ public Long getRegisteredTemplateId(Pair<Hypervisor.HypervisorType, String> hype
371360
}
372361

373362
private static String fetchTemplatesPath() {
374-
String filePath = RELATIVE_TEMPLATE_PATH + METADATA_FILE_NAME;
363+
String filePath = RELATIVE_TEMPLATE_PATH + METADATA_FILE_NAME;
364+
LOGGER.debug(String.format("Looking for file [ %s ] in the classpath.", filePath));
365+
File metaFile = new File(filePath);
366+
String templatePath = null;
367+
if (metaFile.exists()) {
368+
templatePath = RELATIVE_TEMPLATE_PATH;
369+
}
370+
if (templatePath == null) {
371+
filePath = ABSOLUTE_TEMPLATE_PATH + METADATA_FILE_NAME;
372+
metaFile = new File(filePath);
373+
templatePath = ABSOLUTE_TEMPLATE_PATH;
375374
LOGGER.debug(String.format("Looking for file [ %s ] in the classpath.", filePath));
376-
File metaFile = new File(filePath);
377-
String templatePath = null;
378-
if (metaFile.exists()) {
379-
templatePath = RELATIVE_TEMPLATE_PATH;
380-
}
381-
if (templatePath == null) {
382-
filePath = ABSOLUTE_TEMPLATE_PATH + METADATA_FILE_NAME;
383-
metaFile = new File(filePath);
384-
templatePath = ABSOLUTE_TEMPLATE_PATH;
385-
LOGGER.debug(String.format("Looking for file [ %s ] in the classpath.", filePath));
386-
if (!metaFile.exists()) {
387-
String errMsg = String.format("Unable to locate metadata file in your setup at %s", filePath.toString());
388-
LOGGER.error(errMsg);
389-
throw new CloudRuntimeException(errMsg);
390-
}
375+
if (!metaFile.exists()) {
376+
String errMsg = String.format("Unable to locate metadata file in your setup at %s", filePath.toString());
377+
LOGGER.error(errMsg);
378+
throw new CloudRuntimeException(errMsg);
391379
}
380+
}
392381
return templatePath;
393382
}
394383

@@ -481,7 +470,7 @@ private VMTemplateVO createTemplateObjectInDB(SystemVMTemplateDetails details) {
481470
template.setCrossZones(true);
482471
template.setHypervisorType(details.getHypervisorType());
483472
template.setState(VirtualMachineTemplate.State.Inactive);
484-
template.setDeployAsIs(Hypervisor.HypervisorType.VMware.equals(details.getHypervisorType()));
473+
template.setDeployAsIs(false);
485474
template = vmTemplateDao.persist(template);
486475
return template;
487476
}
@@ -577,12 +566,12 @@ private static void readTemplateProperties(String path, SystemVMTemplateDetails
577566
}
578567

579568
private void updateTemplateTablesOnFailure(long templateId) {
580-
VMTemplateVO template = vmTemplateDao.createForUpdate(templateId);
581-
template.setState(VirtualMachineTemplate.State.Inactive);
582-
vmTemplateDao.update(template.getId(), template);
583-
vmTemplateDao.remove(templateId);
584-
TemplateDataStoreVO templateDataStoreVO = templateDataStoreDao.findByTemplate(template.getId(), DataStoreRole.Image);
585-
templateDataStoreDao.remove(templateDataStoreVO.getId());
569+
VMTemplateVO template = vmTemplateDao.createForUpdate(templateId);
570+
template.setState(VirtualMachineTemplate.State.Inactive);
571+
vmTemplateDao.update(template.getId(), template);
572+
vmTemplateDao.remove(templateId);
573+
TemplateDataStoreVO templateDataStoreVO = templateDataStoreDao.findByTemplate(template.getId(), DataStoreRole.Image);
574+
templateDataStoreDao.remove(templateDataStoreVO.getId());
586575
}
587576

588577
public static void unmountStore(String filePath) {
@@ -603,7 +592,7 @@ public static void unmountStore(String filePath) {
603592
}
604593

605594
private void setupTemplate(String templateName, Pair<Hypervisor.HypervisorType, String> hypervisorAndTemplateName,
606-
String destTempFolder) throws CloudRuntimeException {
595+
String destTempFolder) throws CloudRuntimeException {
607596
String setupTmpltScript = Script.findScript(storageScriptsDir, "setup-sysvm-tmplt");
608597
if (setupTmpltScript == null) {
609598
throw new CloudRuntimeException("Unable to find the createtmplt.sh");
@@ -651,7 +640,7 @@ private Long performTemplateRegistrationOperations(Pair<Hypervisor.HypervisorTyp
651640
}
652641

653642
public void registerTemplate(Pair<Hypervisor.HypervisorType, String> hypervisorAndTemplateName,
654-
Pair<String, Long> storeUrlAndId, VMTemplateVO templateVO, String filePath) {
643+
Pair<String, Long> storeUrlAndId, VMTemplateVO templateVO, String filePath) {
655644
Long templateId = null;
656645
try {
657646
templateId = templateVO.getId();
@@ -690,7 +679,13 @@ public void registerTemplate(Pair<Hypervisor.HypervisorType, String> hypervisorA
690679
}
691680
}
692681

693-
public static void parseMetadataFile() {
682+
/**
683+
* This method parses the metadata file consisting of the systemVM templates information
684+
* @return the version of the systemvm template that is to be used. This is done to in order
685+
* to fallback on the latest available version of the systemVM template when there does not
686+
* exist a template corresponding to the current code version.
687+
*/
688+
public static String parseMetadataFile() {
694689
try {
695690
Ini ini = new Ini();
696691
ini.load(new FileReader(METADATA_FILE));
@@ -702,6 +697,8 @@ public static void parseMetadataFile() {
702697
NewTemplateChecksum.put(hypervisorType, section.get("checksum"));
703698
NewTemplateUrl.put(hypervisorType, section.get("downloadurl"));
704699
}
700+
Ini.Section section = ini.get("default");
701+
return section.get("version");
705702
} catch (Exception e) {
706703
String errMsg = String.format("Failed to parse systemVM template metadata file: %s", METADATA_FILE);
707704
LOGGER.error(errMsg, e);
@@ -735,7 +732,7 @@ private void validateTemplates(Set<Hypervisor.HypervisorType> hypervisorsInUse)
735732
}
736733

737734
File tempFile = new File(TEMPLATES_PATH + matchedTemplate);
738-
String templateChecksum = calculateChecksum(tempFile);
735+
String templateChecksum = DigestHelper.calculateChecksum(tempFile);
739736
if (!templateChecksum.equals(NewTemplateChecksum.get(getHypervisorType(hypervisor)))) {
740737
LOGGER.error(String.format("Checksum mismatch: %s != %s ", templateChecksum, NewTemplateChecksum.get(getHypervisorType(hypervisor))));
741738
templatesFound = false;
@@ -812,9 +809,6 @@ public void doInTransactionWithoutResult(final TransactionStatus status) {
812809
private void updateRegisteredTemplateDetails(Long templateId, Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName) {
813810
VMTemplateVO templateVO = vmTemplateDao.findById(templateId);
814811
templateVO.setTemplateType(Storage.TemplateType.SYSTEM);
815-
if (Hypervisor.HypervisorType.VMware == templateVO.getHypervisorType()) {
816-
templateVO.setDeployAsIs(true);
817-
}
818812
boolean updated = vmTemplateDao.update(templateVO.getId(), templateVO);
819813
if (!updated) {
820814
String errMsg = String.format("updateSystemVmTemplates:Exception while updating template with id %s to be marked as 'system'", templateId);
@@ -834,9 +828,6 @@ private void updateRegisteredTemplateDetails(Long templateId, Map.Entry<Hypervis
834828
private void updateTemplateUrlAndChecksum(VMTemplateVO templateVO, Map.Entry<Hypervisor.HypervisorType, String> hypervisorAndTemplateName) {
835829
templateVO.setUrl(NewTemplateUrl.get(hypervisorAndTemplateName.getKey()));
836830
templateVO.setChecksum(NewTemplateChecksum.get(hypervisorAndTemplateName.getKey()));
837-
if (Hypervisor.HypervisorType.VMware == templateVO.getHypervisorType()) {
838-
templateVO.setDeployAsIs(true);
839-
}
840831
boolean updated = vmTemplateDao.update(templateVO.getId(), templateVO);
841832
if (!updated) {
842833
String errMsg = String.format("updateSystemVmTemplates:Exception while updating 'url' and 'checksum' for hypervisor type %s", hypervisorAndTemplateName.getKey().name());

engine/schema/src/main/resources/META-INF/db/schema-41600to41610.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,29 @@ CALL `cloud_usage`.`IDEMPOTENT_ADD_UNIQUE_INDEX`('cloud_usage.usage_volume', 'id
128128
-- Add PK to cloud_usage.usage_vpn_user
129129
CALL `cloud_usage`.`IDEMPOTENT_ADD_COLUMN`('cloud_usage.usage_vpn_user', 'id', 'BIGINT(20) NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`id`)');
130130

131+
UPDATE `cloud`.`vm_template` SET deploy_as_is = 0 WHERE id = 8;
132+
133+
CREATE PROCEDURE `cloud`.`UPDATE_KUBERNETES_NODE_DETAILS`()
134+
BEGIN
135+
DECLARE vmid BIGINT
136+
; DECLARE done TINYINT DEFAULT FALSE
137+
; DECLARE vmidcursor CURSOR FOR SELECT DISTINCT(vm_id) FROM `cloud`.`kubernetes_cluster_vm_map`
138+
; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE
139+
; OPEN vmidcursor
140+
; vmid_loop:LOOP
141+
FETCH NEXT FROM vmidcursor INTO vmid
142+
; IF done THEN
143+
LEAVE vmid_loop
144+
; ELSE
145+
INSERT `cloud`.`user_vm_details` (vm_id, name, value, display) VALUES (vmid, 'controlNodeLoginUser', 'core', 1)
146+
; END IF
147+
; END LOOP
148+
; CLOSE vmidcursor
149+
; END;
150+
151+
CALL `cloud`.`UPDATE_KUBERNETES_NODE_DETAILS`();
152+
DROP PROCEDURE IF EXISTS `cloud`.`UPDATE_KUBERNETES_NODE_DETAILS`;
153+
131154
-- Add support for VMware 7.0.2.0
132155
INSERT IGNORE INTO `cloud`.`hypervisor_capabilities` (uuid, hypervisor_type, hypervisor_version, max_guests_limit, security_group_enabled, max_data_volumes_limit, max_hosts_per_cluster, storage_motion_supported, vm_snapshot_enabled) values (UUID(), 'VMware', '7.0.2.0', 1024, 0, 59, 64, 1, 1);
133156
-- Copy VMware 7.0.1.0 hypervisor guest OS mappings to VMware 7.0.2.0

0 commit comments

Comments
 (0)