-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Keming <[email protected]>
- Loading branch information
Showing
6 changed files
with
106 additions
and
2 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
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,66 @@ | ||
package server | ||
|
||
import ( | ||
_ "embed" | ||
"fmt" | ||
"os/exec" | ||
"path/filepath" | ||
"strings" | ||
"syscall" | ||
"text/template" | ||
) | ||
|
||
//go:embed registries.yaml | ||
var registriesContent string | ||
|
||
const mirrorPath = "/etc/rancher/k3s" | ||
const mirrorFile = "registries.yaml" | ||
|
||
// k3sPrepare install everything required by k3s. | ||
type k3sPrepare struct { | ||
options Options | ||
} | ||
|
||
func (s *k3sPrepare) Run() error { | ||
if !s.options.Mirror.Configured() { | ||
return nil | ||
} | ||
fmt.Fprintf(s.options.OutputStream, "🚧 Configure the mirror...\n") | ||
|
||
tmpl, err := template.New("registries").Parse(registriesContent) | ||
if err != nil { | ||
panic(err) | ||
} | ||
buf := strings.Builder{} | ||
err = tmpl.Execute(&buf, s.options.Mirror) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
cmd := exec.Command("/bin/sh", "-c", fmt.Sprintf( | ||
"sudo mkdir -p %s && sudo tee %s > /dev/null << EOF\n%s\nEOF", | ||
mirrorPath, | ||
filepath.Join(mirrorPath, mirrorFile), | ||
buf.String(), | ||
)) | ||
cmd.SysProcAttr = &syscall.SysProcAttr{ | ||
Pdeathsig: syscall.SIGKILL, | ||
} | ||
if s.options.Verbose { | ||
cmd.Stderr = s.options.OutputStream | ||
cmd.Stdout = s.options.OutputStream | ||
} else { | ||
cmd.Stdout = nil | ||
cmd.Stderr = nil | ||
} | ||
err = cmd.Run() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (s *k3sPrepare) Verify() error { | ||
return nil | ||
} |
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,4 @@ | ||
mirrors: | ||
{{ .Name }}: | ||
endpoint: | ||
{{ range $endpoint := .Endpoints }}- "{{ $endpoint }}"{{ end }} |