Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions hack/build-e2e-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ set -xe
DIR="$(realpath "$(dirname "${0}")")"

cd "${DIR}/../templates/docker"
sudo docker build . -t k8s-snap:dev-old --build-arg BRANCH=main --build-arg KUBERNETES_VERSION=v1.32.1 --build-arg KUBERNETES_VERSION_UPGRADE_TO=v1.33.0
sudo docker build . -t k8s-snap:dev-new --build-arg BRANCH=main --build-arg KUBERNETES_VERSION=v1.33.0
sudo docker build . -t k8s-snap:dev-old --build-arg BRANCH=KU-4167/build-go-versions --build-arg KUBERNETES_VERSION=v1.33.4 --build-arg KUBERNETES_VERSION_UPGRADE_TO=v1.34.0
sudo docker build . -t k8s-snap:dev-new --build-arg BRANCH=KU-4167/build-go-versions --build-arg KUBERNETES_VERSION=v1.34.0
cd -
5 changes: 4 additions & 1 deletion pkg/cloudinit/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ func NewBaseCloudConfig(data BaseUserData) (CloudConfig, error) {

var configFileContents string
if data.BootstrapConfig != "" {
configFileContents = data.BootstrapConfig
configFileContents, err = MergeBootstrapConfigFileContents(data.BootstrapConfig, data.ConfigFileContents)
if err != nil {
return CloudConfig{}, fmt.Errorf("failed to merge bootstrap config contents: %w", err)
}
} else {
configFileContents = data.ConfigFileContents
}
Expand Down
29 changes: 29 additions & 0 deletions pkg/cloudinit/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cloudinit

import (
"fmt"

apiv1 "github.com/canonical/k8s-snap-api/api/v1"
kubeyaml "sigs.k8s.io/yaml"
)

// MergeBootstrapConfigFileContents merges the user-provided bootstrap configuration
// with the generated bootstrap configuration. In case of conflicts, the user-provided
// configuration takes precedence.
func MergeBootstrapConfigFileContents(userConfigStr, generatedConfigStr string) (string, error) {
merged := apiv1.BootstrapConfig{}
if err := kubeyaml.Unmarshal([]byte(generatedConfigStr), &merged); err != nil {
return "", fmt.Errorf("failed to unmarshal generated bootstrap config: %w", err)
}

if err := kubeyaml.Unmarshal([]byte(userConfigStr), &merged); err != nil {
return "", fmt.Errorf("failed to unmarshal user-provided bootstrap config: %w", err)
}

mergedBytes, err := kubeyaml.Marshal(merged)
if err != nil {
return "", fmt.Errorf("failed to marshal final bootstrap config: %w", err)
}

return string(mergedBytes), nil
}
Loading
Loading