-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
145 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/c3os-io/c3os/cli/config" | ||
"github.com/c3os-io/c3os/cli/machine" | ||
"github.com/c3os-io/c3os/cli/machine/openrc" | ||
"github.com/c3os-io/c3os/cli/machine/systemd" | ||
role "github.com/c3os-io/c3os/cli/role" | ||
"github.com/c3os-io/c3os/cli/utils" | ||
) | ||
|
||
func oneTimeBootstrap(c *config.Config) error { | ||
if role.SentinelExist() { | ||
fmt.Println("Sentinel exists, nothing to do. exiting.") | ||
return nil | ||
} | ||
|
||
var svc machine.Service | ||
k3sConfig := config.K3s{} | ||
svcName := "k3s" | ||
svcRole := "server" | ||
|
||
if c.K3s.Enabled { | ||
k3sConfig = c.K3s | ||
} else if c.K3sAgent.Enabled { | ||
k3sConfig = c.K3sAgent | ||
svcName = "k3s-agent" | ||
svcRole = "agent" | ||
} | ||
|
||
if utils.IsOpenRCBased() { | ||
svc, _ = openrc.NewService( | ||
openrc.WithName(svcName), | ||
) | ||
} else { | ||
svc, _ = systemd.NewService( | ||
systemd.WithName(svcName), | ||
) | ||
} | ||
|
||
envFile := fmt.Sprintf("/etc/sysconfig/%s", svcName) | ||
if svc == nil { | ||
return fmt.Errorf("could not detect OS") | ||
} | ||
|
||
// Setup systemd unit and starts it | ||
if err := utils.WriteEnv(envFile, | ||
k3sConfig.Env, | ||
); err != nil { | ||
return err | ||
} | ||
|
||
if err := svc.OverrideCmd(fmt.Sprintf("/usr/bin/k3s %s %s", svcRole, strings.Join(k3sConfig.Args, " "))); err != nil { | ||
return err | ||
} | ||
|
||
if err := svc.SetEnvFile(envFile); err != nil { | ||
return err | ||
} | ||
|
||
if err := svc.Start(); err != nil { | ||
return err | ||
} | ||
|
||
if err := svc.Enable(); err != nil { | ||
return err | ||
} | ||
|
||
return role.CreateSentinel() | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,17 @@ | ||
name: "Default deployment" | ||
# The following configuration | ||
# configures k3s manually with the c3os configuration mechanism. | ||
|
||
stages: | ||
network: | ||
- if: '[ ! -f "/run/cos/recovery_mode" ]' | ||
name: "Setup k3s" | ||
environment_file: "/etc/systemd/system/k3s.service.env" | ||
environment: | ||
FOO: "bar" | ||
systemctl: | ||
start: | ||
- k3s | ||
- commands: | ||
- | | ||
chmod 600 /etc/systemd/system/k3s.service.env | ||
initramfs: | ||
# Disable password, enable only ssh access | ||
- if: '[ ! -d "/home/c3os" ]' | ||
name: "Ensure home directory is present" | ||
commands: | ||
- mkdir /home/c3os | ||
- chmod 755 /home/c3os | ||
- chown -R c3os /home/c3os | ||
- name: "Setup users" | ||
# users: | ||
# root: | ||
# c3os: | ||
# password: "c3os" | ||
authorized_keys: | ||
c3os: | ||
- github:mudler | ||
commands: | ||
- passwd -l c3os | ||
- passwd -l c3os | ||
|
||
k3s: | ||
enabled: true |