underpost 2.8.82 → 2.8.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  import { getNpmRootPath } from '../server/conf.js';
2
2
  import { loggerFactory } from '../server/logger.js';
3
3
  import { shellExec } from '../server/process.js';
4
+ import UnderpostBaremetal from './baremetal.js';
4
5
  import UnderpostDeploy from './deploy.js';
5
6
  import UnderpostTest from './test.js';
6
7
  import os from 'os';
@@ -37,6 +38,7 @@ class UnderpostCluster {
37
38
  * @param {boolean} [options.kubeadm=false] - Initialize the cluster using Kubeadm.
38
39
  * @param {boolean} [options.k3s=false] - Initialize the cluster using K3s.
39
40
  * @param {boolean} [options.initHost=false] - Perform initial host setup (install Docker, Podman, Kind, Kubeadm, Helm).
41
+ * @param {boolean} [options.uninstallHost=false] - Uninstall all host components.
40
42
  * @param {boolean} [options.config=false] - Apply general host configuration (SELinux, containerd, sysctl, firewalld).
41
43
  * @param {boolean} [options.worker=false] - Configure as a worker node (for Kubeadm or K3s join).
42
44
  * @param {boolean} [options.chown=false] - Set up kubectl configuration for the current user.
@@ -65,6 +67,7 @@ class UnderpostCluster {
65
67
  kubeadm: false,
66
68
  k3s: false,
67
69
  initHost: false,
70
+ uninstallHost: false,
68
71
  config: false,
69
72
  worker: false,
70
73
  chown: false,
@@ -73,6 +76,9 @@ class UnderpostCluster {
73
76
  // Handles initial host setup (installing docker, podman, kind, kubeadm, helm)
74
77
  if (options.initHost === true) return UnderpostCluster.API.initHost();
75
78
 
79
+ // Handles initial host setup (installing docker, podman, kind, kubeadm, helm)
80
+ if (options.uninstallHost === true) return UnderpostCluster.API.uninstallHost();
81
+
76
82
  // Applies general host configuration (SELinux, containerd, sysctl)
77
83
  if (options.config === true) return UnderpostCluster.API.config();
78
84
 
@@ -126,7 +132,7 @@ class UnderpostCluster {
126
132
  }
127
133
 
128
134
  // Reset Kubernetes cluster components (Kind/Kubeadm/K3s) and container runtimes
129
- if (options.reset === true) return await UnderpostCluster.API.reset();
135
+ if (options.reset === true) return await UnderpostCluster.API.safeReset({ underpostRoot });
130
136
 
131
137
  // Check if a cluster (Kind, Kubeadm, or K3s) is already initialized
132
138
  const alreadyKubeadmCluster = UnderpostDeploy.API.get('calico-kube-controllers')[0];
@@ -138,6 +144,7 @@ class UnderpostCluster {
138
144
  // This block handles the initial setup of the Kubernetes cluster (control plane or worker).
139
145
  // It prevents re-initialization if a cluster is already detected.
140
146
  if (!options.worker && !alreadyKubeadmCluster && !alreadyKindCluster && !alreadyK3sCluster) {
147
+ UnderpostCluster.API.config();
141
148
  if (options.k3s === true) {
142
149
  logger.info('Initializing K3s control plane...');
143
150
  // Install K3s
@@ -415,8 +422,10 @@ class UnderpostCluster {
415
422
  * This method ensures proper SELinux, Docker, Containerd, and Sysctl settings
416
423
  * are applied for a healthy Kubernetes environment. It explicitly avoids
417
424
  * iptables flushing commands to prevent conflicts with Kubernetes' own network management.
425
+ * @param {string} underpostRoot - The root directory of the underpost project.
418
426
  */
419
- config() {
427
+ config(options = { underpostRoot: '.' }) {
428
+ const { underpostRoot } = options;
420
429
  console.log('Applying host configuration: SELinux, Docker, Containerd, and Sysctl settings.');
421
430
  // Disable SELinux (permissive mode)
422
431
  shellExec(`sudo setenforce 0`);
@@ -426,10 +435,14 @@ class UnderpostCluster {
426
435
  shellExec(`sudo systemctl enable --now docker || true`); // Docker might not be needed for K3s
427
436
  shellExec(`sudo systemctl enable --now kubelet || true`); // Kubelet might not be needed for K3s (K3s uses its own agent)
428
437
 
429
- // Configure containerd for SystemdCgroup
438
+ // Configure containerd for SystemdCgroup and explicitly disable SELinux
430
439
  // This is crucial for kubelet/k3s to interact correctly with containerd
431
440
  shellExec(`containerd config default | sudo tee /etc/containerd/config.toml > /dev/null`);
432
441
  shellExec(`sudo sed -i -e "s/SystemdCgroup = false/SystemdCgroup = true/g" /etc/containerd/config.toml`);
442
+ // Add a new line to disable SELinux for the runc runtime
443
+ // shellExec(
444
+ // `sudo sed -i '/SystemdCgroup = true/a selinux_disabled = true' /etc/containerd/config.toml || true`,
445
+ // );
433
446
  shellExec(`sudo service docker restart || true`); // Restart docker after containerd config changes
434
447
  shellExec(`sudo systemctl enable --now containerd.service`);
435
448
  shellExec(`sudo systemctl restart containerd`); // Restart containerd to apply changes
@@ -447,11 +460,16 @@ class UnderpostCluster {
447
460
  `/etc/sysctl.d/99-k8s-ipforward.conf`,
448
461
  `/etc/sysctl.d/99-k8s.conf`,
449
462
  ])
450
- shellExec(`echo 'net.bridge.bridge-nf-call-iptables = 1
463
+ shellExec(
464
+ `echo 'net.bridge.bridge-nf-call-iptables = 1
451
465
  net.bridge.bridge-nf-call-ip6tables = 1
452
466
  net.bridge.bridge-nf-call-arptables = 1
453
- net.ipv4.ip_forward = 1' | sudo tee ${iptableConfPath}`);
454
- shellExec(`sudo sysctl --system`); // Apply sysctl changes immediately
467
+ net.ipv4.ip_forward = 1' | sudo tee ${iptableConfPath}`,
468
+ { silent: true },
469
+ );
470
+ // shellExec(`sudo sysctl --system`); // Apply sysctl changes immediately
471
+ // Apply NAT iptables rules.
472
+ shellExec(`${underpostRoot}/manifests/maas/nat-iptables.sh`, { silent: true });
455
473
 
456
474
  // Disable firewalld (common cause of network issues in Kubernetes)
457
475
  shellExec(`sudo systemctl stop firewalld || true`); // Stop if running
@@ -492,22 +510,40 @@ net.ipv4.ip_forward = 1' | sudo tee ${iptableConfPath}`);
492
510
  },
493
511
 
494
512
  /**
495
- * @method reset
496
- * @description Performs a comprehensive reset of Kubernetes and container environments.
497
- * This function is for cleaning up a node, reverting changes made by 'kubeadm init', 'kubeadm join', or 'k3s install'.
498
- * It includes deleting Kind clusters, resetting kubeadm, removing CNI configs,
499
- * cleaning Docker and Podman data, persistent volumes, and resetting kubelet components.
500
- * It avoids aggressive iptables flushing that would break host connectivity, relying on kube-proxy's
501
- * control loop to eventually clean up rules if the cluster is not re-initialized.
513
+ * @method safeReset
514
+ * @description Performs a complete reset of the Kubernetes cluster and its container environments.
515
+ * This version focuses on correcting persistent permission errors (such as 'permission denied'
516
+ * in coredns) by restoring SELinux security contexts and safely cleaning up cluster artifacts.
517
+ * @param {object} [options] - Configuration options for the reset.
518
+ * @param {string} [options.underpostRoot] - The root path of the underpost project.
502
519
  */
503
- async reset() {
504
- logger.info('Starting comprehensive reset of Kubernetes and container environments...');
520
+ async safeReset(options = { underpostRoot: '.' }) {
521
+ logger.info('Starting a safe and comprehensive reset of Kubernetes and container environments...');
505
522
 
506
523
  try {
507
- // Phase 1: Pre-reset Kubernetes Cleanup (while API server is still up)
508
- logger.info('Phase 1/6: Cleaning up Kubernetes resources (PVCs, PVs) while API server is accessible...');
524
+ // Phase 0: Truncate large logs under /var/log to free up immediate space
525
+ logger.info('Phase 0/7: Truncating large log files under /var/log...');
526
+ try {
527
+ const cleanPath = `/var/log/`;
528
+ const largeLogsFiles = shellExec(
529
+ `sudo du -sh ${cleanPath}* | awk '{if ($1 ~ /G$/ && ($1+0) > 1) print}' | sort -rh`,
530
+ {
531
+ stdout: true,
532
+ },
533
+ );
534
+ for (const pathLog of largeLogsFiles
535
+ .split(`\n`)
536
+ .map((p) => p.split(cleanPath)[1])
537
+ .filter((p) => p)) {
538
+ shellExec(`sudo rm -rf ${cleanPath}${pathLog}`);
539
+ }
540
+ } catch (err) {
541
+ logger.warn(` -> Error truncating log files: ${err.message}. Continuing with reset.`);
542
+ }
509
543
 
510
- // Get all Persistent Volumes and identify their host paths for data deletion.
544
+ // Phase 1: Clean up Persistent Volumes with hostPath
545
+ // This targets data created by Kubernetes Persistent Volumes that use hostPath.
546
+ logger.info('Phase 1/7: Cleaning Kubernetes hostPath volumes...');
511
547
  try {
512
548
  const pvListJson = shellExec(`kubectl get pv -o json || echo '{"items":[]}'`, { stdout: true, silent: true });
513
549
  const pvList = JSON.parse(pvListJson);
@@ -527,60 +563,66 @@ net.ipv4.ip_forward = 1' | sudo tee ${iptableConfPath}`);
527
563
  } catch (error) {
528
564
  logger.error('Failed to clean up Persistent Volumes:', error);
529
565
  }
530
-
531
- // Phase 2: Stop Kubelet/K3s agent and remove CNI configuration
532
- logger.info('Phase 2/6: Stopping Kubelet/K3s agent and removing CNI configurations...');
533
- shellExec(`sudo systemctl stop kubelet || true`); // Stop kubelet if it's running (kubeadm)
534
- shellExec(`sudo /usr/local/bin/k3s-uninstall.sh || true`); // Run K3s uninstall script if it exists
535
-
536
- // CNI plugins use /etc/cni/net.d to store their configuration.
566
+ // Phase 2: Restore SELinux and stop services
567
+ // This is critical for fixing the 'permission denied' error you experienced.
568
+ // Enable SELinux permissive mode and restore file contexts.
569
+ logger.info('Phase 2/7: Stopping services and fixing SELinux...');
570
+ logger.info(' -> Ensuring SELinux is in permissive mode...');
571
+ shellExec(`sudo setenforce 0 || true`);
572
+ shellExec(`sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config || true`);
573
+ logger.info(' -> Restoring SELinux contexts for container data directories...');
574
+ // The 'restorecon' command corrects file system security contexts.
575
+ shellExec(`sudo restorecon -Rv /var/lib/containerd || true`);
576
+ shellExec(`sudo restorecon -Rv /var/lib/kubelet || true`);
577
+
578
+ logger.info(' -> Stopping kubelet, docker, and podman services...');
579
+ shellExec('sudo systemctl stop kubelet || true');
580
+ shellExec('sudo systemctl stop docker || true');
581
+ shellExec('sudo systemctl stop podman || true');
582
+ // Safely unmount pod filesystems to avoid errors.
583
+ shellExec('sudo umount -f /var/lib/kubelet/pods/*/* || true');
584
+
585
+ // Phase 3: Execute official uninstallation commands
586
+ logger.info('Phase 3/7: Executing official reset and uninstallation commands...');
587
+ logger.info(' -> Executing kubeadm reset...');
588
+ shellExec('sudo kubeadm reset --force || true');
589
+ logger.info(' -> Executing K3s uninstallation script if it exists...');
590
+ shellExec('sudo /usr/local/bin/k3s-uninstall.sh || true');
591
+ logger.info(' -> Deleting Kind clusters...');
592
+ shellExec('kind get clusters | xargs -r -t -n1 kind delete cluster || true');
593
+
594
+ // Phase 4: File system cleanup
595
+ logger.info('Phase 4/7: Cleaning up remaining file system artifacts...');
596
+ // Remove any leftover configurations and data.
597
+ shellExec('sudo rm -rf /etc/kubernetes/* || true');
537
598
  shellExec('sudo rm -rf /etc/cni/net.d/* || true');
538
-
539
- // Phase 3: Kind Cluster Cleanup
540
- logger.info('Phase 3/6: Cleaning up Kind clusters...');
541
- shellExec(`kind get clusters | xargs -r -t -n1 kind delete cluster || true`);
542
-
543
- // Phase 4: Kubeadm Reset (if applicable)
544
- logger.info('Phase 4/6: Performing kubeadm reset (if applicable)...');
545
- shellExec(`sudo kubeadm reset --force || true`); // Use || true to prevent script from failing if kubeadm is not installed
546
-
547
- // Phase 5: Post-reset File System Cleanup (Local Storage, Kubeconfig)
548
- logger.info('Phase 5/6: Cleaning up local storage provisioner data and kubeconfig...');
599
+ shellExec('sudo rm -rf /var/lib/kubelet/* || true');
600
+ shellExec('sudo rm -rf /var/lib/cni/* || true');
601
+ shellExec('sudo rm -rf /var/lib/docker/* || true');
602
+ shellExec('sudo rm -rf /var/lib/containerd/* || true');
603
+ shellExec('sudo rm -rf /var/lib/containers/storage/* || true');
604
+ // Clean up the current user's kubeconfig.
549
605
  shellExec('rm -rf $HOME/.kube || true');
550
- shellExec(`sudo rm -rf /opt/local-path-provisioner/* || true`);
551
-
552
- // Phase 6: Container Runtime Cleanup (Docker and Podman)
553
- logger.info('Phase 6/6: Cleaning up Docker and Podman data...');
554
- shellExec('sudo docker system prune -a -f || true');
555
- shellExec('sudo service docker stop || true');
556
- shellExec(`sudo rm -rf /var/lib/containers/storage/* || true`);
557
- shellExec(`sudo rm -rf /var/lib/docker/volumes/* || true`);
558
- shellExec(`sudo rm -rf /var/lib/docker~/* || true`);
559
- shellExec(`sudo rm -rf /home/containers/storage/* || true`);
560
- shellExec(`sudo rm -rf /home/docker/* || true`);
561
- shellExec('sudo mkdir -p /home/docker || true');
562
- shellExec('sudo chmod 777 /home/docker || true');
563
- shellExec('sudo ln -sf /home/docker /var/lib/docker || true');
564
-
565
- shellExec(`sudo podman system prune -a -f || true`);
566
- shellExec(`sudo podman system prune --all --volumes --force || true`);
567
- shellExec(`sudo podman system prune --external --force || true`);
568
- shellExec(`sudo mkdir -p /home/containers/storage || true`);
569
- shellExec('sudo chmod 0711 /home/containers/storage || true');
570
- shellExec(
571
- `sudo sed -i -e "s@/var/lib/containers/storage@/home/containers/storage@g" /etc/containers/storage.conf || true`,
572
- );
573
- shellExec(`sudo podman system reset -f || true`);
574
-
575
- // Final Kubelet and System Cleanup (after all other operations)
576
- logger.info('Finalizing Kubelet and system file cleanup...');
577
- shellExec(`sudo rm -rf /etc/kubernetes/* || true`);
578
- shellExec(`sudo rm -rf /var/lib/kubelet/* || true`);
579
- shellExec(`sudo rm -rf /root/.local/share/Trash/files/* || true`);
580
- shellExec(`sudo systemctl daemon-reload`);
581
- shellExec(`sudo systemctl start kubelet || true`); // Attempt to start kubelet; might fail if fully reset
582
606
 
583
- logger.info('Comprehensive reset completed successfully.');
607
+ // Phase 5: Host network cleanup
608
+ logger.info('Phase 5/7: Cleaning up host network configurations...');
609
+ // Remove iptables rules and CNI network interfaces.
610
+ shellExec('sudo iptables -F || true');
611
+ shellExec('sudo iptables -t nat -F || true');
612
+ // Restore iptables rules
613
+ shellExec(`chmod +x ${options.underpostRoot}/manifests/maas/nat-iptables.sh`);
614
+ shellExec(`${options.underpostRoot}/manifests/maas/nat-iptables.sh`, { silent: true });
615
+ shellExec('sudo ip link del cni0 || true');
616
+ shellExec('sudo ip link del flannel.1 || true');
617
+
618
+ logger.info('Phase 6/7: Clean up images');
619
+ shellExec(`podman rmi $(podman images -qa) --force`);
620
+
621
+ // Phase 6: Reload daemon and finalize
622
+ logger.info('Phase 7/7: Reloading the system daemon and finalizing...');
623
+ // shellExec('sudo systemctl daemon-reload');
624
+ UnderpostCluster.API.config();
625
+ logger.info('Safe and complete reset finished. The system is ready for a new cluster initialization.');
584
626
  } catch (error) {
585
627
  logger.error(`Error during reset: ${error.message}`);
586
628
  console.error(error);
@@ -623,51 +665,24 @@ net.ipv4.ip_forward = 1' | sudo tee ${iptableConfPath}`);
623
665
  },
624
666
  /**
625
667
  * @method initHost
626
- * @description Installs essential host-level prerequisites for Kubernetes,
627
- * including Docker, Podman, Kind, Kubeadm, and Helm.
628
- *
629
- * Quick-Start Guide for K3s Installation:
630
- * This guide will help you quickly launch a cluster with default options. Make sure your nodes meet the requirements before proceeding.
631
- * Consult the Installation page for greater detail on installing and configuring K3s.
632
- * For information on how K3s components work together, refer to the Architecture page.
633
- * If you are new to Kubernetes, the official Kubernetes docs have great tutorials covering basics that all cluster administrators should be familiar with.
634
- *
635
- * Install Script:
636
- * K3s provides an installation script that is a convenient way to install it as a service on systemd or openrc based systems. This script is available at https://get.k3s.io. To install K3s using this method, just run:
637
- * curl -sfL https://get.k3s.io | sh -
638
- *
639
- * After running this installation:
640
- * - The K3s service will be configured to automatically restart after node reboots or if the process crashes or is killed
641
- * - Additional utilities will be installed, including kubectl, crictl, ctr, k3s-killall.sh, and k3s-uninstall.sh
642
- * - A kubeconfig file will be written to /etc/rancher/k3s/k3s.yaml and the kubectl installed by K3s will automatically use it
643
- *
644
- * A single-node server installation is a fully-functional Kubernetes cluster, including all the datastore, control-plane, kubelet, and container runtime components necessary to host workload pods. It is not necessary to add additional server or agents nodes, but you may want to do so to add additional capacity or redundancy to your cluster.
645
- *
646
- * To install additional agent nodes and add them to the cluster, run the installation script with the K3S_URL and K3S_TOKEN environment variables. Here is an example showing how to join an agent:
647
- * curl -sfL https://get.k3s.io | K3S_URL=https://myserver:6443 K3S_TOKEN=mynodetoken sh -
648
- *
649
- * Setting the K3S_URL parameter causes the installer to configure K3s as an agent, instead of a server. The K3s agent will register with the K3s server listening at the supplied URL. The value to use for K3S_TOKEN is stored at /var/lib/rancher/k3s/server/node-token on your server node.
650
- *
651
- * Note: Each machine must have a unique hostname. If your machines do not have unique hostnames, pass the K3S_NODE_NAME environment variable and provide a value with a valid and unique hostname for each node.
652
- * If you are interested in having more server nodes, see the High Availability Embedded etcd and High Availability External DB pages for more information.
668
+ * @description Installs essential host-level prerequisites for Kubernetes (Docker, Podman, Kind, Kubeadm, Helm).
653
669
  */
654
670
  initHost() {
655
- console.log(
656
- 'Installing essential host-level prerequisites for Kubernetes (Docker, Podman, Kind, Kubeadm, Helm) and providing K3s Quick-Start Guide information...',
657
- );
658
- // Install docker
659
- shellExec(`sudo dnf -y install dnf-plugins-core`);
671
+ const archData = UnderpostBaremetal.API.getHostArch();
672
+ logger.info('Installing essential host-level prerequisites for Kubernetes...', archData);
673
+ // Install Docker and its dependencies
674
+ shellExec(`sudo dnf -y install dnf-plugins-core dbus-x11`);
660
675
  shellExec(`sudo dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo`);
661
676
  shellExec(`sudo dnf -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin`);
662
677
 
663
- // Install podman
678
+ // Install Podman
664
679
  shellExec(`sudo dnf -y install podman`);
665
680
 
666
- // Install kind
667
- shellExec(`[ $(uname -m) = aarch64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.29.0/kind-linux-arm64
681
+ // Install Kind (Kubernetes in Docker)
682
+ shellExec(`[ $(uname -m) = ${archData.name} ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.29.0/kind-linux-${archData.alias}
668
683
  chmod +x ./kind
669
684
  sudo mv ./kind /bin/kind`);
670
- // Install kubeadm, kubelet, kubectl (these are also useful for K3s for kubectl command)
685
+ // Install Kubernetes tools: Kubeadm, Kubelet, and Kubectl
671
686
  shellExec(`cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
672
687
  [kubernetes]
673
688
  name=Kubernetes
@@ -679,14 +694,78 @@ exclude=kubelet kubeadm kubectl cri-tools kubernetes-cni
679
694
  EOF`);
680
695
  shellExec(`sudo yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes`);
681
696
 
682
- // Install helm
697
+ // Install Helm
683
698
  shellExec(`curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3`);
684
699
  shellExec(`chmod 700 get_helm.sh`);
685
700
  shellExec(`./get_helm.sh`);
686
701
  shellExec(`chmod +x /usr/local/bin/helm`);
687
702
  shellExec(`sudo mv /usr/local/bin/helm /bin/helm`);
703
+ shellExec(`sudo rm -rf get_helm.sh`);
688
704
  console.log('Host prerequisites installed successfully.');
689
705
  },
706
+ /**
707
+ * @method uninstallHost
708
+ * @description Uninstalls all host components installed by initHost.
709
+ * This includes Docker, Podman, Kind, Kubeadm, Kubelet, Kubectl, and Helm.
710
+ */
711
+ uninstallHost() {
712
+ console.log('Uninstalling host components: Docker, Podman, Kind, Kubeadm, Kubelet, Kubectl, Helm.');
713
+
714
+ // Remove Kind
715
+ console.log('Removing Kind...');
716
+ shellExec(`sudo rm -f /bin/kind || true`);
717
+
718
+ // Remove Helm
719
+ console.log('Removing Helm...');
720
+ shellExec(`sudo rm -f /usr/local/bin/helm || true`);
721
+ shellExec(`sudo rm -f /usr/local/bin/helm.sh || true`); // clean up the install script if it exists
722
+
723
+ // Remove Docker and its dependencies
724
+ console.log('Removing Docker, containerd, and related packages...');
725
+ shellExec(
726
+ `sudo dnf -y remove docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin || true`,
727
+ );
728
+
729
+ // Remove Podman
730
+ console.log('Removing Podman...');
731
+ shellExec(`sudo dnf -y remove podman || true`);
732
+
733
+ // Remove Kubeadm, Kubelet, and Kubectl
734
+ console.log('Removing Kubernetes tools...');
735
+ shellExec(`sudo yum remove -y kubelet kubeadm kubectl || true`);
736
+
737
+ // Remove Kubernetes repo file
738
+ console.log('Removing Kubernetes repository configuration...');
739
+ shellExec(`sudo rm -f /etc/yum.repos.d/kubernetes.repo || true`);
740
+
741
+ // Clean up Kubeadm config and data directories
742
+ console.log('Cleaning up Kubernetes configuration directories...');
743
+ shellExec(`sudo rm -rf /etc/kubernetes/pki || true`);
744
+ shellExec(`sudo rm -rf ~/.kube || true`);
745
+
746
+ // Stop and disable services
747
+ console.log('Stopping and disabling services...');
748
+ shellExec(`sudo systemctl stop docker.service || true`);
749
+ shellExec(`sudo systemctl disable docker.service || true`);
750
+ shellExec(`sudo systemctl stop containerd.service || true`);
751
+ shellExec(`sudo systemctl disable containerd.service || true`);
752
+ shellExec(`sudo systemctl stop kubelet.service || true`);
753
+ shellExec(`sudo systemctl disable kubelet.service || true`);
754
+
755
+ // Clean up config files
756
+ console.log('Removing host configuration files...');
757
+ shellExec(`sudo rm -f /etc/containerd/config.toml || true`);
758
+ shellExec(`sudo rm -f /etc/sysctl.d/k8s.conf || true`);
759
+ shellExec(`sudo rm -f /etc/sysctl.d/99-k8s-ipforward.conf || true`);
760
+ shellExec(`sudo rm -f /etc/sysctl.d/99-k8s.conf || true`);
761
+
762
+ // Restore SELinux to enforcing
763
+ console.log('Restoring SELinux to enforcing mode...');
764
+ // shellExec(`sudo setenforce 1`);
765
+ // shellExec(`sudo sed -i 's/^SELINUX=permissive$/SELINUX=enforcing/' /etc/selinux/config`);
766
+
767
+ console.log('Uninstall process completed.');
768
+ },
690
769
  };
691
770
  }
692
771
  export default UnderpostCluster;
package/src/cli/deploy.js CHANGED
@@ -296,6 +296,11 @@ kind: StatefulSet
296
296
  metadata:
297
297
  name: ...
298
298
  EOF
299
+
300
+ https://org.ngc.nvidia.com/setup/api-keys
301
+ docker login nvcr.io
302
+ Username: $oauthtoken
303
+ Password: <Your Key>
299
304
  `);
300
305
  if (deployList === 'dd' && fs.existsSync(`./engine-private/deploy/dd.router`))
301
306
  deployList = fs.readFileSync(`./engine-private/deploy/dd.router`, 'utf8');
@@ -514,6 +519,15 @@ node bin/deploy build-full-client ${deployId}
514
519
  logger.error(error, error.stack);
515
520
  }
516
521
  },
522
+ existsContainerFile({ podName, path }) {
523
+ return JSON.parse(
524
+ shellExec(`kubectl exec ${podName} -- test -f ${path} && echo "true" || echo "false"`, {
525
+ stdout: true,
526
+ disableLog: true,
527
+ silent: true,
528
+ }).trim(),
529
+ );
530
+ },
517
531
  };
518
532
  }
519
533
 
package/src/cli/index.js CHANGED
@@ -4,9 +4,9 @@ import Underpost from '../index.js';
4
4
  import { getNpmRootPath, getUnderpostRootPath, loadConf } from '../server/conf.js';
5
5
  import fs from 'fs-extra';
6
6
  import { commitData } from '../client/components/core/CommonJs.js';
7
- import { shellExec } from '../server/process.js';
8
7
  import UnderpostLxd from './lxd.js';
9
8
  import UnderpostBaremetal from './baremetal.js';
9
+ import UnderpostRun from './run.js';
10
10
 
11
11
  // Load environment variables from .env file
12
12
  const underpostRootPath = getUnderpostRootPath();
@@ -128,6 +128,7 @@ program
128
128
  .option('--info-capacity-pod', 'Displays the current machine capacity information per pod.')
129
129
  .option('--pull-image', 'Sets an optional associated image to pull during initialization.')
130
130
  .option('--init-host', 'Installs necessary Kubernetes node CLI tools (e.g., kind, kubeadm, docker, podman, helm).')
131
+ .option('--uninstall-host', 'Uninstalls all host components installed by init-host.')
131
132
  .option('--config', 'Sets the base Kubernetes node configuration.')
132
133
  .option('--worker', 'Sets the context for a worker node.')
133
134
  .option('--chown', 'Sets the appropriate ownership for Kubernetes kubeconfig files.')
@@ -314,6 +315,23 @@ program
314
315
  .description('Manages health server monitoring for specified deployments.')
315
316
  .action(Underpost.monitor.callback);
316
317
 
318
+ // 'run' command: Run a script
319
+ program
320
+ .command('run')
321
+ .argument('<runner-id>', `The runner ID to run. Options: ${Object.keys(UnderpostRun.RUNNERS).join(', ')}.`)
322
+ .argument('[path]', 'The absolute or relative directory path where the script is located.')
323
+ .option('--command <command-array>', 'Array of commands to run.')
324
+ .option('--args <args-array>', 'Array of arguments to pass to the command.')
325
+ .option('--dev', 'Sets the development context environment for the script.')
326
+ .option('--pod-name <pod-name>', 'Optional: Specifies the pod name for test execution.')
327
+ .option('--volume-host-path <volume-host-path>', 'Optional: Specifies the volume host path for test execution.')
328
+ .option('--volume-mount-path <volume-mount-path>', 'Optional: Specifies the volume mount path for test execution.')
329
+ .option('--image-name <image-name>', 'Optional: Specifies the image name for test execution.')
330
+ .option('--container-name <container-name>', 'Optional: Specifies the container name for test execution.')
331
+ .option('--namespace <namespace>', 'Optional: Specifies the namespace for test execution.')
332
+ .description('Runs a script from the specified path.')
333
+ .action(UnderpostRun.API.callback);
334
+
317
335
  // 'lxd' command: LXD management
318
336
  program
319
337
  .command('lxd')
@@ -60,7 +60,7 @@ class UnderpostRepository {
60
60
  },
61
61
 
62
62
  push(repoPath = './', gitUri = 'underpostnet/pwa-microservices-template', options = { f: false, g8: false }) {
63
- const gExtension = options.g8 === true ? '.g8' : '.git';
63
+ const gExtension = options.g8 === true || options.G8 === true ? '.g8' : '.git';
64
64
  shellExec(
65
65
  `cd ${repoPath} && git push https://${process.env.GITHUB_TOKEN}@github.com/${gitUri}${gExtension}${
66
66
  options?.f === true ? ' --force' : ''
@@ -71,9 +71,12 @@ class UnderpostRepository {
71
71
  );
72
72
  logger.info(
73
73
  'commit url',
74
- `http://github.com/${gitUri}/commit/${shellExec(`cd ${repoPath} && git rev-parse --verify HEAD`, {
75
- stdout: true,
76
- }).trim()}`,
74
+ `http://github.com/${gitUri}${gExtension === '.g8' ? '.g8' : ''}/commit/${shellExec(
75
+ `cd ${repoPath} && git rev-parse --verify HEAD`,
76
+ {
77
+ stdout: true,
78
+ },
79
+ ).trim()}`,
77
80
  );
78
81
  },
79
82