Skip to content

Commit

Permalink
Use YAML content for Elemental Agent config
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Mazzotti <[email protected]>
  • Loading branch information
anmazzotti committed Jun 19, 2024
1 parent 0939fb0 commit 12a73c2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 29 deletions.
38 changes: 23 additions & 15 deletions cmd/support/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,20 @@ import (
)

const (
k3sKubeConfig = "/etc/rancher/k3s/k3s.yaml"
k3sKubectl = "/usr/local/bin/kubectl"
rkeKubeConfig = "/etc/rancher/rke2/rke2.yaml"
rkeKubectl = "/var/lib/rancher/rke2/bin/kubectl"
elementalAgentPlanDir = "/var/lib/elemental/agent/applied/"
rancherAgentPlanDir = "/var/lib/rancher/agent/applied/"
rancherAgentConf = "/etc/rancher/agent/config.yaml"
elementalAgentConf = "/etc/rancher/agent/config.yaml"
osRelease = "/etc/os-release"
hostnameFile = "/etc/hostname"
resolvConf = "/etc/resolv.conf"
oemDir = "/oem/"
systemOEMDir = "/system/oem"
k3sKubeConfig = "/etc/rancher/k3s/k3s.yaml"
k3sKubectl = "/usr/local/bin/kubectl"
rkeKubeConfig = "/etc/rancher/rke2/rke2.yaml"
rkeKubectl = "/var/lib/rancher/rke2/bin/kubectl"
elementalAgentPlanDir = "/var/lib/elemental/agent/applied/"
rancherAgentPlanDir = "/var/lib/rancher/agent/applied/"
rancherAgentConf = "/etc/rancher/agent/config.yaml"
elementalAgentConfYAML = "/etc/rancher/elemental/agent/config.yaml" //Before 1.6.x config
elementalAgentConfJSON = "/etc/rancher/elemental/agent/config.json"
osRelease = "/etc/os-release"
hostnameFile = "/etc/hostname"
resolvConf = "/etc/resolv.conf"
oemDir = "/oem/"
systemOEMDir = "/system/oem"
)

func getServices() []string {
Expand Down Expand Up @@ -138,8 +139,15 @@ func run() (err error) {
copyFile(f, tempDir)
}

log.Infof("Copying %s", elementalAgentConf)
copyFileWithAltName(elementalAgentConf, tempDir, "elemental-agent-config.yaml")
if existsNoWarn(elementalAgentConfYAML) {
log.Infof("Copying %s", elementalAgentConfYAML)
copyFileWithAltName(elementalAgentConfYAML, tempDir, "elemental-agent-config.yaml")
}
if existsNoWarn(elementalAgentConfJSON) {
log.Infof("Copying %s", elementalAgentConfJSON)
copyFileWithAltName(elementalAgentConfJSON, tempDir, "elemental-agent-config.json")
}

log.Infof("Copying %s", rancherAgentConf)
copyFileWithAltName(rancherAgentConf, tempDir, "rancher-agent-config.yaml")

Expand Down
24 changes: 12 additions & 12 deletions internal/system-agent/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ type HTTPGetAction struct {
}

type AgentConfig struct {
WorkDir string `json:"workDirectory,omitempty"`
LocalEnabled bool `json:"localEnabled,omitempty"`
LocalPlanDir string `json:"localPlanDirectory,omitempty"`
AppliedPlanDir string `json:"appliedPlanDirectory,omitempty"`
RemoteEnabled bool `json:"remoteEnabled,omitempty"`
ConnectionInfoFile string `json:"connectionInfoFile,omitempty"`
PreserveWorkDir bool `json:"preserveWorkDirectory,omitempty"`
ImagesDir string `json:"imagesDirectory,omitempty"`
AgentRegistriesFile string `json:"agentRegistriesFile,omitempty"`
ImageCredentialProviderConfig string `json:"imageCredentialProviderConfig,omitempty"`
ImageCredentialProviderBinDir string `json:"imageCredentialProviderBinDirectory,omitempty"`
InterlockDir string `json:"interlockDirectory,omitempty"`
WorkDir string `json:"workDirectory,omitempty" yaml:"workDirectory,omitempty"`
LocalEnabled bool `json:"localEnabled,omitempty" yaml:"localEnabled,omitempty"`
LocalPlanDir string `json:"localPlanDirectory,omitempty" yaml:"localPlanDirectory,omitempty"`
AppliedPlanDir string `json:"appliedPlanDirectory,omitempty" yaml:"appliedPlanDirectory,omitempty"`
RemoteEnabled bool `json:"remoteEnabled,omitempty" yaml:"remoteEnabled,omitempty"`
ConnectionInfoFile string `json:"connectionInfoFile,omitempty" yaml:"connectionInfoFile,omitempty"`
PreserveWorkDir bool `json:"preserveWorkDirectory,omitempty" yaml:"preserveWorkDirectory,omitempty"`
ImagesDir string `json:"imagesDirectory,omitempty" yaml:"imagesDirectory,omitempty"`
AgentRegistriesFile string `json:"agentRegistriesFile,omitempty" yaml:"agentRegistriesFile,omitempty"`
ImageCredentialProviderConfig string `json:"imageCredentialProviderConfig,omitempty" yaml:"imageCredentialProviderConfig,omitempty"`
ImageCredentialProviderBinDir string `json:"imageCredentialProviderBinDirectory,omitempty" yaml:"imageCredentialProviderBinDirectory,omitempty"`
InterlockDir string `json:"interlockDirectory,omitempty" yaml:"interlockDirectory,omitempty"`
}

type ConnectionInfo struct {
Expand Down
7 changes: 6 additions & 1 deletion pkg/install/_testdata/system-agent-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ stages:
permissions: 384
owner: 0
group: 0
content: '{"workDirectory":"/var/lib/elemental/agent/work","localPlanDirectory":"/var/lib/elemental/agent/plans","appliedPlanDirectory":"/var/lib/elemental/agent/applied","remoteEnabled":true,"connectionInfoFile":"/var/lib/elemental/agent/elemental_connection.json"}'
content: |
workDirectory: /var/lib/elemental/agent/work
localPlanDirectory: /var/lib/elemental/agent/plans
appliedPlanDirectory: /var/lib/elemental/agent/applied
remoteEnabled: true
connectionInfoFile: /var/lib/elemental/agent/elemental_connection.json
encoding: ""
ownerstring: ""
2 changes: 1 addition & 1 deletion pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func (i *installer) getAgentConfigBytes() ([]byte, error) {
PreserveWorkDir: false,
}

agentConfigBytes, err := json.Marshal(agentConfig)
agentConfigBytes, err := yaml.Marshal(agentConfig)
if err != nil {
return nil, fmt.Errorf("encoding agentConfig: %w", err)
}
Expand Down

0 comments on commit 12a73c2

Please sign in to comment.