Skip to content

Commit

Permalink
Remove support for automatic kubelet restart
Browse files Browse the repository at this point in the history
Previously, if the system started without a kubernetes configuration
file, kiOS would start kubelet then watch for the configuration file to
appear. Once it did, it would auto restart the kubelet.

While this was a nice "magic" feature, it had a couple of drawbacks:

- It required bootstrap containers to be aware that they need to write
  the config file last - this is not always clear
- It was relatively black and white - auto restarting only works when
  the system has no configuration at all. Partial configuration could
  not use this method.
- Restarting the container runtime could not be done using this method
- The implementation was poor

For the moment, therefore, this functionality is removed - instead
bootstrap containers should explicitly restart the kubelet by requesting
it via the system socket.
  • Loading branch information
EmilyShepherd committed Jul 22, 2023
1 parent 3a5d045 commit 3b5d290
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
19 changes: 19 additions & 0 deletions pkgs/bin/init/src/exe.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "include/kmsg.h"

#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
Expand All @@ -13,6 +14,23 @@ int should_restart_processes = 1;
pid_t crio_pid;
pid_t kubelet_pid;

/**
* Set Hostname From File
*
* Checks to see if /etc/hostname exists and contains content - if it
* does the hostname is updated.
*/
static void set_hostname_from_file(void) {
char hostname[HOST_NAME_MAX];
FILE *fp = fopen("/etc/hostname", "r");
if (fp) {
if (fgets(hostname, HOST_NAME_MAX, fp)) {
sethostname(hostname, strlen(hostname));
}
fclose(fp);
}
}

/**
* Start Exe
*
Expand Down Expand Up @@ -190,6 +208,7 @@ void start_kubelet(void) {
SET_ARG("--image-credential-provider-bin-dir", KUBELET_CREDENTIAL_PROVIDER_BIN_DIR);
}

set_hostname_from_file();
kubelet_pid = start_exe("/bin/kubelet", KUBELET_LOG, kubeletArgs);
}

Expand Down
26 changes: 0 additions & 26 deletions pkgs/bin/init/src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,6 @@
#include <stdio.h>
#include <stdlib.h>

/**
* Set Hostname From File
*
* Checks to see if /etc/hostname exists and contains content - if it
* does the hostname is updated.
*/
static void set_hostname_from_file(void) {
char hostname[HOST_NAME_MAX];
FILE *fp = fopen("/etc/hostname", "r");
if (fp) {
if (fgets(hostname, HOST_NAME_MAX, fp)) {
sethostname(hostname, strlen(hostname));
}
fclose(fp);
}
}

/**
* Enable IP Forwarding
*
Expand Down Expand Up @@ -90,7 +73,6 @@ int main(int argc, char **argv) {
// reasonable to do so. All our other init steps are performed in that
// three second window.
bring_if_up("eth0");
set_hostname_from_file();
enable_ip_forwarding();
start_socket();
signal(SIGTERM, &soft_shutdown);
Expand All @@ -99,14 +81,6 @@ int main(int argc, char **argv) {
// Now we are finished with our own setup, wait for crio to be ready.
wait_for_path(CRIO_SOCK);

if (!fexists(KUBELET_CONFIG)) {
start_kubelet();
wait_for_path(KUBELET_CONFIG);
set_hostname_from_file();

stop_kubelet();
}

start_kubelet();
run_wait_loop();
}

0 comments on commit 3b5d290

Please sign in to comment.