Skip to content

Commit ee1e643

Browse files
committed
Add options for local user data
Now it's possible to use a local userdata folder. This is mostly useful for development to avoid updating the user data Secrets all the time.
1 parent 9b4e1f7 commit ee1e643

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

pkg/cloud/openstack/options/options.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ import (
2222
)
2323

2424
var (
25-
TokenTTL time.Duration
25+
TokenTTL time.Duration
26+
UserDataFolder string
27+
UserDataPostprocessor string
2628
)
2729

2830
func init() {
2931
flag.DurationVar(&TokenTTL, "token_ttl", 60*time.Minute, "TTL for kubeadm bootstrap token of the target Kubernetes cluster")
32+
flag.StringVar(&UserDataFolder, "user-data-folder", "", "if set, user data files are retrieved from <user-data-folder>/<machine-name>.yaml")
33+
flag.StringVar(&UserDataPostprocessor, "user-data-postprocessor", "", "postprocessor to user for the user data")
3034
}

pkg/cloud/openstack/services/userdata/machinescript.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ import (
2020
"bytes"
2121
"context"
2222
"errors"
23+
"io/ioutil"
2324
"k8s.io/client-go/kubernetes"
2425
"k8s.io/client-go/tools/clientcmd"
2526
"k8s.io/klog"
27+
"path"
2628
"sigs.k8s.io/cluster-api-provider-openstack/pkg/cloud/openstack/options"
2729
"sigs.k8s.io/cluster-api-provider-openstack/pkg/deployer"
2830
"sigs.k8s.io/cluster-api/pkg/util"
@@ -108,6 +110,15 @@ func GetUserData(controllerClient client.Client, kubeClient kubernetes.Interface
108110
p, postprocess = userDataSecret.Data[PostprocessorKey]
109111

110112
postprocessor = string(p)
113+
} else if options.UserDataFolder != "" {
114+
userData, err = ioutil.ReadFile(path.Join(options.UserDataFolder, fmt.Sprintf("%s.yaml", machine.Name)))
115+
if err != nil {
116+
return "", fmt.Errorf("could not load local userdata files: %v", err)
117+
}
118+
postprocessor = options.UserDataPostprocessor
119+
if postprocessor != "" {
120+
postprocess = true
121+
}
111122
}
112123

113124
var userDataRendered string

0 commit comments

Comments
 (0)