Open
Conversation
Collaborator
vikasbolla
commented
Mar 3, 2026
- Added a Cloud init script, which creates a User Profile and handles configuration required for ssh-key based authentication.
5373f89 to
a59c42a
Compare
a59c42a to
aa13928
Compare
Signed-off-by: Vikas <vikas.satyanarayana.bolla@ibm.com>
aa13928 to
055b441
Compare
Member
Prajyot-Parab
left a comment
There was a problem hiding this comment.
/lgtm
/hold for @mkumatag
mkumatag
requested changes
Mar 3, 2026
| memory := float64(vmSpec.Capacity.Memory) | ||
| processors, _ := strconv.ParseFloat(vmSpec.Capacity.CPU, 64) | ||
| var userData string | ||
| if strings.HasPrefix(vmSpec.Image, IbmiImagePrefix) { |
Member
There was a problem hiding this comment.
for the long run - introduce some filed like os
| return nil | ||
| } | ||
|
|
||
| func getUserData(sshKeys []string, username string) string { |
Member
There was a problem hiding this comment.
make use of text/template package like below(refer only template logic)
package main
import (
_ "embed"
"flag"
"fmt"
"os"
"text/template"
)
//go:embed cloud-init-template.txt
var cloudInitTemplate string
// Config holds the template variables
type Config struct {
Username string
Keys string
}
func main() {
// Define command-line flags
username := flag.String("username", "", "Username for the cloud-init configuration (required)")
keys := flag.String("keys", "", "SSH public keys (required)")
output := flag.String("output", "", "Output file path (optional, defaults to stdout)")
flag.Parse()
// Validate required parameters
if *username == "" {
fmt.Fprintln(os.Stderr, "Error: -username is required")
flag.Usage()
os.Exit(1)
}
if *keys == "" {
fmt.Fprintln(os.Stderr, "Error: -keys is required")
flag.Usage()
os.Exit(1)
}
// Create config with provided values
config := Config{
Username: *username,
Keys: *keys,
}
// Parse the embedded template
tmpl, err := template.New("cloud-init").Parse(cloudInitTemplate)
if err != nil {
fmt.Fprintf(os.Stderr, "Error parsing template: %v\n", err)
os.Exit(1)
}
// Determine output destination
var writer *os.File
if *output != "" {
writer, err = os.Create(*output)
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating output file: %v\n", err)
os.Exit(1)
}
defer writer.Close()
} else {
writer = os.Stdout
}
// Execute template with config values
err = tmpl.Execute(writer, config)
if err != nil {
fmt.Fprintf(os.Stderr, "Error executing template: %v\n", err)
os.Exit(1)
}
// Print success message if writing to file
if *output != "" {
fmt.Fprintf(os.Stderr, "Cloud-init configuration successfully written to: %s\n", *output)
}
}
// Made with Bob| } | ||
|
|
||
| // Fallback to raw script if template reading fails for some reason | ||
| return fmt.Sprintf(`#cloud-config |
Member
There was a problem hiding this comment.
no need to fallback, it will not fail..
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.