generated from LinuxSuRen/github-go
-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
1 parent
00936e7
commit de9d6c4
Showing
7 changed files
with
179 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package apt | ||
|
||
import ( | ||
// Enable go embed | ||
_ "embed" | ||
"fmt" | ||
"github.com/linuxsuren/http-downloader/pkg/exec" | ||
"io" | ||
"io/ioutil" | ||
"net/http" | ||
"runtime" | ||
) | ||
|
||
//go:embed resource/kubernetes.list | ||
var kuberneteList string | ||
|
||
// kubectlInstallerInUbuntu is the installer of kubectl in CentOS | ||
type kubectlInstallerInUbuntu struct { | ||
count int | ||
} | ||
|
||
// Available check if support current platform | ||
func (d *kubectlInstallerInUbuntu) Available() (ok bool) { | ||
if runtime.GOOS == "linux" { | ||
_, err := exec.LookPath("apt-get") | ||
ok = err == nil | ||
} | ||
return | ||
} | ||
|
||
func fetchKeyring() (err error) { | ||
var response *http.Response | ||
if response, err = http.Get("https://packages.cloud.google.com/apt/doc/apt-key.gpg"); err != nil { | ||
err = fmt.Errorf("failed to download kubernetes apt-key.gpg, error: %v", err) | ||
return | ||
} | ||
|
||
var data []byte | ||
if data, err = io.ReadAll(response.Body); err != nil { | ||
err = fmt.Errorf("failed to read response body from apt-key.gpg, error: %v", err) | ||
return | ||
} | ||
|
||
keyring := "/usr/share/keyrings/kubernetes-archive-keyring.gpg" | ||
if err = ioutil.WriteFile(keyring, data, 0644); err != nil { | ||
err = fmt.Errorf("failed to save %s, error: %v", keyring, err) | ||
} | ||
return | ||
} | ||
|
||
// Install installs the kubectl | ||
func (d *kubectlInstallerInUbuntu) Install() (err error) { | ||
if err = fetchKeyring(); err != nil { | ||
err = fmt.Errorf("failed to save kubernetes-archive-kerying.gpg") | ||
return | ||
} | ||
|
||
repo := "/etc/apt/sources.list.d/kubernetes.list" | ||
if err = ioutil.WriteFile(repo, []byte(kuberneteList), 0644); err != nil { | ||
err = fmt.Errorf("failed to save %s, error: %v", repo, err) | ||
return | ||
} | ||
|
||
if err = exec.RunCommand("apt-get", "update", "-y"); err != nil { | ||
return | ||
} | ||
if err = exec.RunCommand("apt-get", "install", "-y", "apt-transport-https", | ||
"ca-certificates"); err != nil { | ||
return | ||
} | ||
if err = exec.RunCommand("apt-get", "update", "-y"); err != nil { | ||
return | ||
} | ||
if err = exec.RunCommand("apt-get", "install", "-y", "kubectl"); err != nil { | ||
return | ||
} | ||
return | ||
} | ||
|
||
// Uninstall uninstalls the kubectl | ||
func (d *kubectlInstallerInUbuntu) Uninstall() (err error) { | ||
err = exec.RunCommand("apt-get", "remove", "-y", "kubectl") | ||
return | ||
} | ||
|
||
// WaitForStart waits for the service be started | ||
func (d *kubectlInstallerInUbuntu) WaitForStart() (ok bool, err error) { | ||
ok = true | ||
return | ||
} | ||
|
||
// Start starts the kubectl service | ||
func (d *kubectlInstallerInUbuntu) Start() error { | ||
fmt.Println("not supported yet") | ||
return nil | ||
} | ||
|
||
// Stop stops the kubectl service | ||
func (d *kubectlInstallerInUbuntu) Stop() error { | ||
fmt.Println("not supported yet") | ||
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 @@ | ||
deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main |
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,65 @@ | ||
package yum | ||
|
||
import ( | ||
// Enable go embed | ||
_ "embed" | ||
"fmt" | ||
"github.com/linuxsuren/http-downloader/pkg/exec" | ||
"io/ioutil" | ||
"runtime" | ||
) | ||
|
||
//go:embed resource/kubernetes.repo | ||
var kubernetesRepo string | ||
|
||
// kubectlInstallerInCentOS is the installer of kubectl in CentOS | ||
type kubectlInstallerInCentOS struct { | ||
count int | ||
} | ||
|
||
// Available check if support current platform | ||
func (d *kubectlInstallerInCentOS) Available() (ok bool) { | ||
if runtime.GOOS == "linux" { | ||
_, err := exec.LookPath("yum") | ||
ok = err == nil | ||
} | ||
return | ||
} | ||
|
||
// Install installs the kubectl | ||
func (d *kubectlInstallerInCentOS) Install() (err error) { | ||
repo := "/etc/yum.repos.d/kubernetes.repo" | ||
if err = ioutil.WriteFile(repo, []byte(kubernetesRepo), 0644); err != nil { | ||
err = fmt.Errorf("failed to save %s, error: %v", repo, err) | ||
return | ||
} | ||
|
||
if err = exec.RunCommand("yum", "install", "-y", "kubectl"); err != nil { | ||
return | ||
} | ||
return | ||
} | ||
|
||
// Uninstall uninstalls the kubectl | ||
func (d *kubectlInstallerInCentOS) Uninstall() (err error) { | ||
err = exec.RunCommand("yum", "remove", "-y", "kubectl") | ||
return | ||
} | ||
|
||
// WaitForStart waits for the service be started | ||
func (d *kubectlInstallerInCentOS) WaitForStart() (ok bool, err error) { | ||
ok = true | ||
return | ||
} | ||
|
||
// Start starts the kubectl service | ||
func (d *kubectlInstallerInCentOS) Start() error { | ||
fmt.Println("not supported yet") | ||
return nil | ||
} | ||
|
||
// Stop stops the kubectl service | ||
func (d *kubectlInstallerInCentOS) Stop() error { | ||
fmt.Println("not supported yet") | ||
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,7 @@ | ||
[kubernetes] | ||
name=Kubernetes | ||
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 | ||
enabled=1 | ||
gpgcheck=1 | ||
repo_gpgcheck=1 | ||
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg |