-
Notifications
You must be signed in to change notification settings - Fork 17
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
85a9ba2
commit d2e0b88
Showing
5 changed files
with
104 additions
and
6 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,80 @@ | ||
package k3s | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
provisionerutil "github.com/distributed-containers-inc/sanic/provisioners/util" | ||
"github.com/pkg/errors" | ||
"os" | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
//ProvisionerK3s starts k3s server | ||
type ProvisionerK3s struct { | ||
} | ||
|
||
//EnsureCluster just ensures the registry is running | ||
func (provisioner *ProvisionerK3s) EnsureCluster() error { | ||
return provisionerutil.StartRegistry(provisioner, context.Background(), map[string]string{"node-role.kubernetes.io/master": "true"}) | ||
} | ||
|
||
//KubectlCommand for k3s is just a wrapper around "k3s kubectl" | ||
func (provisioner *ProvisionerK3s) KubectlCommand(args ...string) (*exec.Cmd, error) { | ||
if _, err := exec.LookPath("k3s"); err != nil { | ||
return nil, errors.Wrap(err, "could not find k3s executable in path - is it installed?") | ||
} | ||
cmd := exec.Command("k3s", append([]string{"kubectl"}, args...)...) | ||
cmd.Env = os.Environ() | ||
|
||
return cmd, nil | ||
} | ||
|
||
func (provisioner *ProvisionerK3s) Registry() (registryAddr string, registryInsecure bool, err error) { | ||
cmd, err := provisioner.KubectlCommand( | ||
"get", "service", | ||
"--namespace", "kube-system", | ||
"sanic-registry", | ||
"--output", "jsonpath={.spec.clusterIP}", | ||
) | ||
if err != nil { | ||
return | ||
} | ||
out, err := cmd.Output() | ||
if err != nil { | ||
return | ||
} | ||
ip := strings.TrimSpace(string(out)) | ||
if ip == "" { | ||
err = fmt.Errorf("could not connect to registry - try 'sanic deploy' and waiting 90 seconds") | ||
return | ||
} | ||
registryAddr = fmt.Sprintf("%s:5000", ip) | ||
registryInsecure = true | ||
return | ||
} | ||
|
||
func (provisioner *ProvisionerK3s) EdgeNodes() ([]string, error) { | ||
cmd, err := provisioner.KubectlCommand( | ||
"get", "services", | ||
"-n", "kube-system", | ||
"-o", "jsonpath={.spec.clusterIP}", | ||
"traefik", | ||
) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "could not get the traefik service") | ||
} | ||
out, err := cmd.Output() | ||
if err != nil { | ||
return nil, errors.Wrap(err, "could not get the traefik service") | ||
} | ||
ip := strings.TrimSpace(string(out)) | ||
if ip == "" { | ||
return nil, fmt.Errorf("could not get the IP of the traefik service") | ||
} | ||
return []string{ip}, nil | ||
} | ||
|
||
func (provisioner *ProvisionerK3s) InClusterDir(hostDir string) string { | ||
return hostDir //k3s runs the server on the computer itself | ||
} |
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