Skip to content

Commit

Permalink
rename pkg => nodeconfigutils
Browse files Browse the repository at this point in the history
  • Loading branch information
r2k1 committed Nov 18, 2024
1 parent def0c5c commit 39ea1b4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions aks-node-controller/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"path/filepath"

"github.com/Azure/agentbaker/aks-node-controller/parser"
"github.com/Azure/agentbaker/aks-node-controller/pkg"
"github.com/Azure/agentbaker/aks-node-controller/pkg/nodeconfigutils"
"gopkg.in/fsnotify.v1"
)

Expand Down Expand Up @@ -81,7 +81,7 @@ func (a *App) Provision(ctx context.Context, flags ProvisionFlags) error {
return fmt.Errorf("open provision file %s: %w", flags.ProvisionConfig, err)
}

config, err := pkg.Unmarshal(inputJSON)
config, err := nodeconfigutils.UnmarshalConfigurationV1(inputJSON)
if err != nil {
return fmt.Errorf("unmarshal provision config: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions aks-node-controller/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"testing"

"github.com/Azure/agentbaker/aks-node-controller/helpers"
"github.com/Azure/agentbaker/aks-node-controller/pkg"
aksnodeconfigv1 "github.com/Azure/agentbaker/aks-node-controller/pkg/gen/aksnodeconfig/v1"
"github.com/Azure/agentbaker/aks-node-controller/pkg/nodeconfigutils"
"github.com/Azure/agentbaker/pkg/agent/datamodel"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -458,9 +458,9 @@ func TestContractCompatibilityHandledByProtobuf(t *testing.T) {
t.Run("marshal/unmarshal", func(t *testing.T) {
content, err := os.ReadFile("./testdata/test_aksnodeconfig.json")
require.NoError(t, err)
cfg, err := pkg.Unmarshal(content)
cfg, err := nodeconfigutils.UnmarshalConfigurationV1(content)
require.NoError(t, err)
marshalled, err := pkg.Marshal(cfg)
marshalled, err := nodeconfigutils.MarshalConfigurationV1(cfg)
require.NoError(t, err)
assert.JSONEq(t, string(content), string(marshalled))
})
Expand All @@ -480,7 +480,7 @@ func loadAKSNodeConfig(jsonFilePath string) *aksnodeconfigv1.Configuration {
if err != nil {
log.Fatal(err)
}
cfg, err := pkg.Unmarshal(content)
cfg, err := nodeconfigutils.UnmarshalConfigurationV1(content)
if err != nil {
log.Printf("Failed to unmarshal the aksnodeconfigv1 from json: %v", err)
}
Expand Down
13 changes: 7 additions & 6 deletions aks-node-controller/pkg/nodeconfigutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (
)

const (
scriptlessCustomDataTemplate = `#cloud-config
cloudConfigTemplate = `#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"
cse = "/opt/azure/containers/aks-node-controller provision-wait"
)

func CustomData(cfg *aksnodeconfigv1.Configuration) (string, error) {
Expand All @@ -26,15 +26,15 @@ func CustomData(cfg *aksnodeconfigv1.Configuration) (string, error) {
return "", fmt.Errorf("failed to marshal nbc, error: %w", err)
}
encodedNBCJson := base64.StdEncoding.EncodeToString(nbcJSON)
customDataYAML := fmt.Sprintf(scriptlessCustomDataTemplate, encodedNBCJson)
customDataYAML := fmt.Sprintf(cloudConfigTemplate, encodedNBCJson)
return base64.StdEncoding.EncodeToString([]byte(customDataYAML)), nil
}

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

func Marshal(cfg *aksnodeconfigv1.Configuration) ([]byte, error) {
func MarshalConfigurationV1(cfg *aksnodeconfigv1.Configuration) ([]byte, error) {
options := protojson.MarshalOptions{
UseEnumNumbers: false,
UseProtoNames: true,
Expand All @@ -43,7 +43,7 @@ func Marshal(cfg *aksnodeconfigv1.Configuration) ([]byte, error) {
return options.Marshal(cfg)
}

func Unmarshal(data []byte) (*aksnodeconfigv1.Configuration, error) {
func UnmarshalConfigurationV1(data []byte) (*aksnodeconfigv1.Configuration, error) {
cfg := &aksnodeconfigv1.Configuration{}
options := protojson.UnmarshalOptions{}
err := options.Unmarshal(data, cfg)
Expand All @@ -52,6 +52,7 @@ func Unmarshal(data []byte) (*aksnodeconfigv1.Configuration, error) {

func Validate(cfg *aksnodeconfigv1.Configuration) error {
requiredStrings := map[string]string{
"version": cfg.GetVersion(),
"auth_config.subscription_id": cfg.GetAuthConfig().GetSubscriptionId(),
"cluster_config.resource_group": cfg.GetClusterConfig().GetResourceGroup(),
"cluster_config.location": cfg.GetClusterConfig().GetLocation(),
Expand Down

0 comments on commit 39ea1b4

Please sign in to comment.