From 8d68c22968a2152c4333c27251d503cc42626efa Mon Sep 17 00:00:00 2001 From: Lily Pan Date: Mon, 4 Nov 2024 10:11:46 -0800 Subject: [PATCH] fix merge conflicts --- aks-node-controller/app.go | 52 +++++++++++++++++++++++++++++++++-- aks-node-controller/const.go | 2 +- aks-node-controller/main.go | 8 +----- e2e/config/config.go | 2 +- e2e/node_bootstrapper_test.go | 12 ++++---- pkg/agent/const.go | 4 +-- 6 files changed, 61 insertions(+), 19 deletions(-) diff --git a/aks-node-controller/app.go b/aks-node-controller/app.go index 1ddbd84f23d..a1a01b4c3be 100644 --- a/aks-node-controller/app.go +++ b/aks-node-controller/app.go @@ -11,9 +11,11 @@ import ( "log/slog" "os" "os/exec" + "path/filepath" "github.com/Azure/agentbaker/aks-node-controller/parser" aksnodeconfigv1 "github.com/Azure/agentbaker/pkg/proto/aksnodeconfig/v1" + "gopkg.in/fsnotify.v1" ) type App struct { @@ -58,6 +60,11 @@ func (a *App) run(ctx context.Context, args []string) error { return errors.New("--provision-config is required") } return a.Provision(ctx, ProvisionFlags{ProvisionConfig: *provisionConfig}) + case "provision-wait": + provisionOutput, err := a.ProvisionWait(ctx) + fmt.Println(provisionOutput) + slog.Info("provision-wait finished", "provisionOutput", provisionOutput) + return err default: return fmt.Errorf("unknown command: %s", args[1]) } @@ -66,7 +73,7 @@ func (a *App) run(ctx context.Context, args []string) error { func (a *App) Provision(ctx context.Context, flags ProvisionFlags) error { inputJSON, err := os.ReadFile(flags.ProvisionConfig) if err != nil { - return fmt.Errorf("open proision file %s: %w", flags.ProvisionConfig, err) + return fmt.Errorf("open provision file %s: %w", flags.ProvisionConfig, err) } config := &aksnodeconfigv1.Configuration{} @@ -95,6 +102,48 @@ func (a *App) Provision(ctx context.Context, flags ProvisionFlags) error { return err } +func (a *App) ProvisionWait(ctx context.Context) (string, error) { + if _, err := os.Stat(provisionJSONFilePath); err == nil { + data, err := os.ReadFile(provisionJSONFilePath) + if err != nil { + return "", err + } + return string(data), nil + } + + watcher, err := fsnotify.NewWatcher() + if err != nil { + return "", fmt.Errorf("failed to create watcher: %w", err) + } + defer watcher.Close() + + // Watch the directory containing the provision complete file + dir := filepath.Dir(provisionCompleteFilePath) + err = os.MkdirAll(dir, 0755) // create the directory if it doesn't exist + if err != nil { + return "", err + } + if err = watcher.Add(dir); err != nil { + return "", fmt.Errorf("failed to watch directory: %w", err) + } + + for { + select { + case event := <-watcher.Events: + if event.Op&fsnotify.Create == fsnotify.Create && event.Name == provisionCompleteFilePath { + data, err := os.ReadFile(provisionJSONFilePath) + if err != nil { + return "", err + } + return string(data), nil + } + + case err := <-watcher.Errors: + return "", fmt.Errorf("error watching file: %w", err) + } + } +} + var _ ExitCoder = &exec.ExitError{} type ExitCoder interface { @@ -111,5 +160,4 @@ func errToExitCode(err error) int { return exitErr.ExitCode() } return 1 - } diff --git a/aks-node-controller/const.go b/aks-node-controller/const.go index ae25caa2b90..4d46c48d804 100644 --- a/aks-node-controller/const.go +++ b/aks-node-controller/const.go @@ -3,7 +3,7 @@ package main // Some options are intentionally non-configurable to avoid customization by users // it will help us to avoid introducing any breaking changes in the future. const ( - logFile = "/var/log/azure/node-bootstrapper.log" + logFile = "/var/log/azure/aks-node-controller.log" bootstrapService = "bootstrap.service" provisionJSONFilePath = "/var/log/azure/aks/provision.json" provisionCompleteFilePath = "/opt/azure/containers/provision.complete" diff --git a/aks-node-controller/main.go b/aks-node-controller/main.go index ffa2ab02154..1ac2d2fdf73 100644 --- a/aks-node-controller/main.go +++ b/aks-node-controller/main.go @@ -7,14 +7,8 @@ import ( "os" ) -// Some options are intentionally non-configurable to avoid customization by users -// it will help us to avoid introducing any breaking changes in the future. -const ( - LogFile = "/var/log/azure/aks-node-controller.log" -) - func main() { - logFile, err := os.OpenFile(LogFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + logFile, err := os.OpenFile(logFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) if err != nil { //nolint:forbidigo // there is no other way to communicate the error fmt.Printf("failed to open log file: %s\n", err) diff --git a/e2e/config/config.go b/e2e/config/config.go index 54eca55cf16..b3590c53743 100644 --- a/e2e/config/config.go +++ b/e2e/config/config.go @@ -37,7 +37,7 @@ type Configuration struct { KeepVMSS bool `env:"KEEP_VMSS"` BlobStorageAccountPrefix string `env:"BLOB_STORAGE_ACCOUNT_PREFIX" envDefault:"abe2e"` BlobContainer string `env:"BLOB_CONTAINER" envDefault:"abe2e"` - NodeBootstrapperTestMode string `env:"NODE_BOOTSTRAPPER_TEST_MODE"` // "provision" or "provision-wait" + AKSNodeControllerTestMode string `env:"AKS_NODE_CONTROLLER_TEST_MODE"` // "provision" or "provision-wait" } func (c *Configuration) BlobStorageAccount() string { diff --git a/e2e/node_bootstrapper_test.go b/e2e/node_bootstrapper_test.go index b30173822ae..320397c6faf 100644 --- a/e2e/node_bootstrapper_test.go +++ b/e2e/node_bootstrapper_test.go @@ -28,8 +28,8 @@ import ( // mostly executed locally func Test_ubuntu2204AKSNodeController(t *testing.T) { ctx := newTestCtx(t) - if config.Config.NodeBootstrapperTestMode == "" { - t.Skip("NODE_BOOTSTRAPPER_TEST_MODE not set") + if config.Config.AKSNodeControllerTestMode == "" { + t.Skip("AKS_NODE_CONTROLLER_TEST_MODE not set") } // TODO: figure out how to properly parallelize test, maybe move t.Parallel to the top of each test? cluster, err := ClusterKubenet(ctx, t) @@ -48,10 +48,10 @@ func Test_ubuntu2204AKSNodeController(t *testing.T) { require.NoError(t, err) var cse string - if config.Config.NodeBootstrapperTestMode == "provision" { - cse = CSENodeBootstrapper(t, cluster) - } else if config.Config.NodeBootstrapperTestMode == "provision-wait" { - cse = "./node-bootstrapper provision-wait" + if config.Config.AKSNodeControllerTestMode == "provision" { + cse = CSEAKSNodeController(t, cluster) + } else if config.Config.AKSNodeControllerTestMode == "provision-wait" { + cse = "./aks-node-controller provision-wait" } RunScenario(t, &Scenario{ diff --git a/pkg/agent/const.go b/pkg/agent/const.go index c829bd9705b..4af7535931d 100644 --- a/pkg/agent/const.go +++ b/pkg/agent/const.go @@ -114,10 +114,10 @@ const ( ) const ( - scriptlessBootstrapStatusCSE = "/opt/azure/containers/node-bootstrapper provision-wait" + scriptlessBootstrapStatusCSE = "/opt/azure/containers/aks-node-controller provision-wait" scriptlessCustomDataTemplate = `#cloud-config write_files: -- path: /opt/azure/containers/node-bootstrapper-config.json +- path: /opt/azure/containers/aks-node-controller-config.json permissions: "0755" owner: root content: !!binary |