Skip to content

Commit

Permalink
combine files into one
Browse files Browse the repository at this point in the history
  • Loading branch information
r2k1 committed Nov 18, 2024
1 parent cb76ae7 commit def0c5c
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 81 deletions.
34 changes: 0 additions & 34 deletions aks-node-controller/pkg/bootstrap.go

This file was deleted.

22 changes: 0 additions & 22 deletions aks-node-controller/pkg/json.go

This file was deleted.

69 changes: 69 additions & 0 deletions aks-node-controller/pkg/nodeconfigutils/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package nodeconfigutils

import (
"encoding/base64"
"encoding/json"
"fmt"

aksnodeconfigv1 "github.com/Azure/agentbaker/aks-node-controller/pkg/gen/aksnodeconfig/v1"
"google.golang.org/protobuf/encoding/protojson"
)

const (
scriptlessCustomDataTemplate = `#cloud-config
write_files:
- path: /opt/azure/containers/aks-node-controller-config.json
permissions: "0755"
owner: root
content: !!binary |
%s`
scriptlessBootstrapStatusCSE = "/opt/azure/containers/aks-node-controller provision-wait"
)

func CustomData(cfg *aksnodeconfigv1.Configuration) (string, error) {
nbcJSON, err := json.Marshal(cfg)
if err != nil {
return "", fmt.Errorf("failed to marshal nbc, error: %w", err)
}
encodedNBCJson := base64.StdEncoding.EncodeToString(nbcJSON)
customDataYAML := fmt.Sprintf(scriptlessCustomDataTemplate, encodedNBCJson)
return base64.StdEncoding.EncodeToString([]byte(customDataYAML)), nil
}

func CSE(cfg *aksnodeconfigv1.Configuration) (string, error) {
return scriptlessBootstrapStatusCSE, nil
}

func Marshal(cfg *aksnodeconfigv1.Configuration) ([]byte, error) {
options := protojson.MarshalOptions{
UseEnumNumbers: false,
UseProtoNames: true,
Indent: " ",
}
return options.Marshal(cfg)
}

func Unmarshal(data []byte) (*aksnodeconfigv1.Configuration, error) {
cfg := &aksnodeconfigv1.Configuration{}
options := protojson.UnmarshalOptions{}
err := options.Unmarshal(data, cfg)
return cfg, err
}

func Validate(cfg *aksnodeconfigv1.Configuration) error {
requiredStrings := map[string]string{
"auth_config.subscription_id": cfg.GetAuthConfig().GetSubscriptionId(),
"cluster_config.resource_group": cfg.GetClusterConfig().GetResourceGroup(),
"cluster_config.location": cfg.GetClusterConfig().GetLocation(),
"cluster_config.cluster_network_config.vnet_name": cfg.GetClusterConfig().GetClusterNetworkConfig().GetVnetName(),
"cluster_config.cluster_network_config.route_table": cfg.GetClusterConfig().GetClusterNetworkConfig().GetRouteTable(),
"api_server_config.api_server_name": cfg.GetApiServerConfig().GetApiServerName(),
}

for field, value := range requiredStrings {
if value == "" {
return fmt.Errorf("required field %v is missing", field)
}
}
return nil
}
25 changes: 0 additions & 25 deletions aks-node-controller/pkg/validate.go

This file was deleted.

0 comments on commit def0c5c

Please sign in to comment.