Skip to content

Commit

Permalink
Merge pull request #303 from akutz/feature/inline-cloud-init
Browse files Browse the repository at this point in the history
  • Loading branch information
akutz authored Dec 14, 2023
2 parents b5d6e6e + 7769b25 commit 70d22b9
Show file tree
Hide file tree
Showing 19 changed files with 1,698 additions and 269 deletions.
51 changes: 42 additions & 9 deletions api/v1alpha2/cloudinit/cloudconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,51 @@
package cloudinit

import (
"encoding/json"

"github.com/vmware-tanzu/vm-operator/api/v1alpha2/common"
)

// CloudConfig is the VM Operator API subset of a Cloud-Init CloudConfig and
// contains several of the CloudConfig's frequently user modules.
// contains several of the CloudConfig's frequently used modules.
type CloudConfig struct {
// Timezone describes the timezone represented in /usr/share/zoneinfo.
//
// +optional
Timezone string `json:"timezone,omitempty"`

// User enables overriding the "default_user" configuration from
// "/etc/cloud/cloud.cfg".
// AlwaysDefaultUser may be set to true to ensure even if the Users field
// is not empty, the default user is still created on systems that have one
// defined. By default, Cloud-Init ignores the default user if the
// CloudConfig provides one or more non-default users via the Users field.
//
// +optional
User User `json:"user,omitempty"`
AlwaysDefaultUser bool `json:"defaultUser,omitempty"`

// Users allows adding/configuring one or more users on the guest.
//
// Please note if the first element in this list has a Name field set to
// "default", then that element will be serialized as "- default" when
// marshaling this list as part of generating a YAML CloudConfig.
//
// +optional
// +listType=map
// +listMapKey=name
Users []User `json:"users,omitempty"`

// RunCmd allows running one or more commands on the guest.
// The entries in this list can adhere to two, different formats:
//
// Format 1 -- a string that contains the command and its arguments, ex.
//
// runcmd:
// - "ls -al"
//
// Format 2 -- a list of the command and its arguments, ex.
//
// runcmd:
// - - echo
// - "Hello, world."
//
// +optional
RunCmd []json.RawMessage `json:"runcmd,omitempty"`

// WriteFiles
//
// +optional
Expand Down Expand Up @@ -241,8 +258,24 @@ type WriteFile struct {
// When omitted an empty file will be created or existing file will be
// modified.
//
// The value for this field can adhere to two, different formats:
//
// Format 1 -- a string that contains the command and its arguments, ex.
//
// content: Hello, world.
//
// Please note that format 1 supports all of the manners of specifying a
// YAML string.
//
// Format 2 -- a secret reference with the name of the key that contains
// the content for the file, ex.
//
// content:
// name: my-bootstrap-secret
// key: my-file-content
//
// +optional
Content *common.ValueOrSecretKeySelector `json:"content,omitempty"`
Content json.RawMessage `json:"content,omitempty"`

// Defer indicates to defer writing the file until Cloud-Init's "final"
// stage, after users are created and packages are installed.
Expand Down
17 changes: 14 additions & 3 deletions api/v1alpha2/cloudinit/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

225 changes: 35 additions & 190 deletions config/crd/bases/vmoperator.vmware.com_virtualmachines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -720,176 +720,35 @@ spec:
CloudConfig, used to bootstrap the VM. \n Please note this
field and RawCloudConfig are mutually exclusive."
properties:
defaultUser:
description: AlwaysDefaultUser may be set to true to ensure
even if the Users field is not empty, the default user
is still created on systems that have one defined. By
default, Cloud-Init ignores the default user if the
CloudConfig provides one or more non-default users via
the Users field.
type: boolean
runcmd:
description: "RunCmd allows running one or more commands
on the guest. The entries in this list can adhere to
two, different formats: \n Format 1 -- a string that
contains the command and its arguments, ex. \n runcmd:
- \"ls -al\" \n Format 2 -- a list of the command and
its arguments, ex. \n runcmd: - - echo - \"Hello, world.\""
items:
description: RawMessage is a raw encoded JSON value.
It implements Marshaler and Unmarshaler and can be
used to delay JSON decoding or precompute a JSON encoding.
format: byte
type: string
type: array
timezone:
description: Timezone describes the timezone represented
in /usr/share/zoneinfo.
type: string
user:
description: User enables overriding the "default_user"
configuration from "/etc/cloud/cloud.cfg".
properties:
create_groups:
description: "CreateGroups is a flag that may be set
to false to disable creation of specified user groups.
\n Defaults to true when Name is not \"default\"."
type: boolean
expiredate:
description: ExpireData is the date on which the user's
account will be disabled.
type: string
gecos:
description: Gecos is an optional comment about the
user, usually a comma-separated string of the user's
real name and contact information.
type: string
groups:
description: Groups is an optional list of groups
to add to the user.
items:
type: string
type: array
hashed_passwd:
description: HashedPasswd is a hash of the user's
password that will be applied even if the specified
user already exists.
properties:
key:
description: Key is the key in the secret that
specifies the requested data.
type: string
name:
description: Name is the name of the secret.
type: string
required:
- key
- name
type: object
homedir:
description: "Homedir is the optional home directory
for the user. \n Defaults to \"/home/<username>\"
when Name is not \"default\"."
type: string
inactive:
description: Inactive optionally represents the number
of days until the user is disabled.
format: int32
type: integer
lock_passwd:
description: "LockPasswd disables password login.
\n Defaults to true when Name is not \"default\"."
type: boolean
name:
description: "Name is the user's login name. \n Please
note this field may be set to the special value
of \"default\" when this User is the first element
in the Users list from the CloudConfig. When set
to \"default\", all other fields from this User
must be nil."
type: string
no_create_home:
description: "NoCreateHome prevents the creation of
the home directory. \n Defaults to false when Name
is not \"default\"."
type: boolean
no_log_init:
description: "NoLogInit prevents the initialization
of lastlog and faillog for the user. \n Defaults
to false when Name is not \"default\"."
type: boolean
no_user_group:
description: "NoUserGroup prevents the creation of
the group named after the user. \n Defaults to false
when Name is not \"default\"."
type: boolean
passwd:
description: Passwd is a hash of the user's password
that will be applied only to a newly created user.
To apply a new, hashed password to an existing user
please use HashedPasswd instead.
properties:
key:
description: Key is the key in the secret that
specifies the requested data.
type: string
name:
description: Name is the name of the secret.
type: string
required:
- key
- name
type: object
primary_group:
description: "PrimaryGroup is the primary group for
the user. \n Defaults to the value of the Name field
when it is not \"default\"."
type: string
selinux_user:
description: SELinuxUser is the SELinux user for the
user's login.
type: string
shell:
description: "Shell is the path to the user's login
shell. \n Please note the default is to set no shell,
which results in a system-specific default being
used."
type: string
snapuser:
description: "SnapUser specifies an e-mail address
to create the user as a Snappy user through \"snap
create-user\". \n If an Ubuntu SSO account is associated
with the address, the username and SSH keys will
be requested from there."
type: string
ssh_authorized_keys:
description: "SSHAuthorizedKeys is a list of SSH keys
to add to the user's authorized keys file. \n Please
note this field may not be combined with SSHRedirectUser."
items:
type: string
type: array
ssh_import_id:
description: "SSHImportID is a list of SSH IDs to
import for the user. \n Please note this field may
not be combined with SSHRedirectUser."
items:
type: string
type: array
ssh_redirect_user:
description: "SSHRedirectUser may be set to true to
disable SSH logins for this user. \n Please note
that when specified, all SSH keys from cloud meta-data
will be configured in a disabled state for this
user. Any SSH login as this user will timeout with
a message to login instead as the default user.
\n This field may not be combined with SSHAuthorizedKeys
or SSHImportID. \n Defaults to false when Name is
not \"default\"."
type: boolean
sudo:
description: "Sudo is a sudo rule to apply to the
user. \n When omitted, no sudo rules will be applied
to the user."
type: string
system:
description: "System is an optional flag that indicates
the user should be created as a system user with
no home directory. \n Defaults to false when Name
is not \"default\"."
type: boolean
uid:
description: "UID is the user's ID. \n When omitted
the guest will default to the next available number."
format: int64
type: integer
required:
- name
type: object
users:
description: "Users allows adding/configuring one or more
users on the guest. \n Please note if the first element
in this list has a Name field set to \"default\", then
that element will be serialized as \"- default\" when
marshaling this list as part of generating a YAML CloudConfig."
description: Users allows adding/configuring one or more
users on the guest.
items:
description: User is a CloudConfig user data structure.
properties:
Expand Down Expand Up @@ -1070,31 +929,17 @@ spec:
description: "Content is the optional content to
write to the provided Path. \n When omitted an
empty file will be created or existing file will
be modified."
properties:
from:
description: "From is specified to reference
a value from a Secret resource. \n Please
note this field is mutually exclusive with
the Value field."
properties:
key:
description: Key is the key in the secret
that specifies the requested data.
type: string
name:
description: Name is the name of the secret.
type: string
required:
- key
- name
type: object
value:
description: "Value is used to directly specify
a value. \n Please note this field is mutually
exclusive with the From field."
type: string
type: object
be modified. \n The value for this field can adhere
to two, different formats: \n Format 1 -- a string
that contains the command and its arguments, ex.
\n content: Hello, world. \n Please note that
format 1 supports all of the manners of specifying
a YAML string. \n Format 2 -- a secret reference
with the name of the key that contains the content
for the file, ex. \n content: name: my-bootstrap-secret
key: my-file-content"
format: byte
type: string
defer:
description: Defer indicates to defer writing the
file until Cloud-Init's "final" stage, after users
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ require (
sigs.k8s.io/yaml v1.3.0
)

require gopkg.in/yaml.v3 v3.0.1

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
Expand Down Expand Up @@ -82,7 +84,6 @@ require (
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/component-base v0.28.0 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
Expand Down
Loading

0 comments on commit 70d22b9

Please sign in to comment.