Skip to content

Commit 605db3f

Browse files
committed
Added cloud-config template option to override
1 parent d963e3c commit 605db3f

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

cmd/image/qcow2ova/prep/prepare.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ package prep
1616

1717
import (
1818
"fmt"
19-
"github.com/ppc64le-cloud/pvsadm/pkg/utils"
2019
"io/ioutil"
2120
"os"
2221
"path/filepath"
2322
"strings"
2423

24+
"github.com/ppc64le-cloud/pvsadm/pkg/utils"
25+
2526
"k8s.io/klog/v2"
2627
)
2728

@@ -101,7 +102,7 @@ func prepare(mnt, volume, dist, rhnuser, rhnpasswd, rootpasswd string) error {
101102
return err
102103
}
103104

104-
err = ioutil.WriteFile(filepath.Join(mnt, "/etc/cloud/cloud.cfg"), []byte(cloudConfig), 0644)
105+
err = ioutil.WriteFile(filepath.Join(mnt, "/etc/cloud/cloud.cfg"), []byte(CloudConfig), 0644)
105106
if err != nil {
106107
return err
107108
}

cmd/image/qcow2ova/prep/templates.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ mv /etc/resolv.conf.orig /etc/resolv.conf || true
8282
touch /.autorelabel
8383
`
8484

85-
var cloudConfig = `# latest file from cloud-init-22.1-1.el8.noarch
85+
var CloudConfig = `# latest file from cloud-init-22.1-1.el8.noarch
8686
users:
8787
- default
8888

cmd/image/qcow2ova/qcow2ova.go

+14
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ Examples:
6161
# Step 2 - Make the necessary changes to the above generated template file(bash shell script) - image-prep.template
6262
# Step 3 - Run the qcow2ova with the modified image preparation template
6363
pvsadm image qcow2ova --image-name centos-82 --image-dist centos --image-url /root/CentOS-8-GenericCloud-8.2.2004-20200611.2.ppc64le.qcow2 --prep-template image-prep.template
64+
65+
# Convert image with user defined cloud config template.
66+
pvsadm image qcow2ova --image-name centos-82 --image-dist centos --image-url /root/CentOS-8-GenericCloud-8.2.2004-20200611.2.ppc64le.qcow2 --cloud-config user_cloud.config
67+
68+
6469
6570
Qcow2 images location:
6671
@@ -92,7 +97,15 @@ Qcow2 images location:
9297
prep.SetupTemplate = string(content)
9398
}
9499
}
100+
if opt.CloudConfig != "" {
101+
klog.V(2).Info("Overriding with the user defined cloud config.")
102+
content, err := ioutil.ReadFile(opt.CloudConfig)
103+
if err != nil {
104+
return err
105+
}
106+
prep.CloudConfig = string(content)
95107

108+
}
96109
if !utils.Contains([]string{"rhel", "centos", "coreos"}, strings.ToLower(opt.ImageDist)) {
97110
klog.Errorln("--image-dist is a mandatory flag and one of these [rhel, centos, coreos]")
98111
os.Exit(1)
@@ -269,6 +282,7 @@ func init() {
269282
Cmd.Flags().BoolVar(&pkg.ImageCMDOptions.PrepTemplateDefault, "prep-template-default", false, "Prints the default image preparation script template, use --prep-template to set the custom template script(supported distros: rhel and centos)")
270283
Cmd.Flags().StringSliceVar(&pkg.ImageCMDOptions.PreflightSkip, "skip-preflight-checks", []string{}, "Skip the preflight checks(e.g: diskspace, platform, tools) - dev-only option")
271284
Cmd.Flags().BoolVar(&pkg.ImageCMDOptions.OSPasswordSkip, "skip-os-password", false, "Skip the root user password")
285+
Cmd.Flags().StringVar(&pkg.ImageCMDOptions.CloudConfig, "cloud-config", "", "Cloud-config, use --cloud-config to set the custom cloud config")
272286
_ = Cmd.Flags().MarkHidden("skip-preflight-checks")
273287
_ = Cmd.MarkFlagRequired("image-name")
274288
_ = Cmd.MarkFlagRequired("image-url")

pkg/options.go

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ type imageCMDOptions struct {
5252
TempDir string
5353
PrepTemplate string
5454
PrepTemplateDefault bool
55+
CloudConfig string
5556
OSPasswordSkip bool
5657
//upload options
5758
InstanceName string

0 commit comments

Comments
 (0)