-
Notifications
You must be signed in to change notification settings - Fork 1
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
89e8631
commit b199f50
Showing
4 changed files
with
91 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package provisioner | ||
|
||
import ( | ||
"fmt" | ||
"log/slog" | ||
|
||
"github.com/ryota-sakamoto/kubernetes-on-multipass/pkg/cloudinit" | ||
"github.com/ryota-sakamoto/kubernetes-on-multipass/pkg/multipass" | ||
) | ||
|
||
func LaunchInstance(clusterName string, config Config, cloudinitConfig cloudinit.Config) (string, error) { | ||
name := config.Name | ||
if name == "" { | ||
name = GetRandomName() | ||
} | ||
|
||
instanceName := fmt.Sprintf("%s-%s", clusterName, name) | ||
|
||
instance, err := multipass.GetInstance(instanceName) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to get instance: %w", err) | ||
} | ||
|
||
slog.Debug("get instance", slog.String("instanceName", instanceName), slog.Any("instance", instance)) | ||
if instance != nil { | ||
return "", fmt.Errorf("instance already exists: %s", instanceName) | ||
} | ||
|
||
template, err := cloudinit.Generate(GetWorkerTemplate(), map[string]string{ | ||
"KubernetesVersion": config.K8sVersion, | ||
"Arch": "amd64", | ||
}) | ||
if err != nil { | ||
return "", fmt.Errorf("failed to generate cloud-init template: %w", err) | ||
} | ||
|
||
return instanceName, multipass.LaunchInstance(multipass.InstanceConfig{ | ||
Name: instanceName, | ||
CPUs: config.CPUs, | ||
Memory: config.Memory, | ||
Disk: config.Disk, | ||
Image: config.Image, | ||
}, template) | ||
} |