Skip to content

Commit

Permalink
fix merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
Lily Pan committed Nov 4, 2024
1 parent b349ff1 commit 8d68c22
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 19 deletions.
52 changes: 50 additions & 2 deletions aks-node-controller/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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])
}
Expand All @@ -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{}
Expand Down Expand Up @@ -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 {
Expand All @@ -111,5 +160,4 @@ func errToExitCode(err error) int {
return exitErr.ExitCode()
}
return 1

}
2 changes: 1 addition & 1 deletion aks-node-controller/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 1 addition & 7 deletions aks-node-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion e2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
12 changes: 6 additions & 6 deletions e2e/node_bootstrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down

0 comments on commit 8d68c22

Please sign in to comment.