Skip to content

Commit

Permalink
Merge pull request #18 from NVIDIA/containerdversion
Browse files Browse the repository at this point in the history
Fix initial release
  • Loading branch information
ArangoGutierrez committed Feb 20, 2024
2 parents 3957e15 + 5374d68 commit 9c212e1
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 54 deletions.
13 changes: 9 additions & 4 deletions cmd/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,13 @@ func runProvision(log *logger.FunLogger, opts *options) error {
}

// Download kubeconfig
if opts.cfg.Spec.Kubernetes.Install && opts.cfg.Spec.Kubernetes.KubeConfig != "" {
if opts.cfg.Spec.Kubernetes.Install && (opts.cfg.Spec.Kubernetes.KubeConfig != "" || opts.kubeconfig != "") {
if opts.cfg.Spec.Kubernetes.KubernetesInstaller == "microk8s" || opts.cfg.Spec.Kubernetes.KubernetesInstaller == "kind" {
log.Warning("kubeconfig is not supported for %s, skipping kubeconfig download", opts.cfg.Spec.Kubernetes.KubernetesInstaller)
return nil
}

if err = getKubeConfig(log, opts, p); err != nil {
if err = getKubeConfig(log, opts, hostUrl); err != nil {
return fmt.Errorf("failed to get kubeconfig: %v", err)
}
}
Expand All @@ -200,7 +200,7 @@ func runProvision(log *logger.FunLogger, opts *options) error {
}

// getKubeConfig downloads the kubeconfig file from the remote host
func getKubeConfig(log *logger.FunLogger, opts *options, p *provisioner.Provisioner) error {
func getKubeConfig(log *logger.FunLogger, opts *options, hostUrl string) error {
remoteFilePath := "/home/ubuntu/.kube/config"
if opts.cfg.Spec.Kubernetes.KubeConfig == "" {
// and
Expand All @@ -215,7 +215,12 @@ func getKubeConfig(log *logger.FunLogger, opts *options, p *provisioner.Provisio
}
}

// Create a session
// Create a new ssh session
p, err := provisioner.New(log, opts.cfg.Spec.Auth.PrivateKey, opts.cfg.Spec.Auth.Username, hostUrl)
if err != nil {
return err
}

session, err := p.Client.NewSession()
if err != nil {
return fmt.Errorf("error creating session: %v", err)
Expand Down
10 changes: 5 additions & 5 deletions examples/v1alpha1_environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ metadata:
spec:
provider: aws
auth:
keyName: eduardoa
privateKey: "/Users/eduardoa/.ssh/eduardoa.pem"
keyName: cnt-ci
privateKey: "/Users/eduardoa/.ssh/cnt-ci.pem"
instance:
type: g4dn.xlarge
region: eu-north-1
region: us-west-1
ingressIpRanges:
- 213.179.129.0/26
- 0.0.0.0/0
image:
architecture: amd64
imageId: ami-0fe8bec493a81c7da
imageId: ami-0ce2cb35386fc22e9
kubernetes:
install: true
installer: kubeadm
Expand Down
71 changes: 38 additions & 33 deletions pkg/provider/aws/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,40 +40,45 @@ func (a *Client) Delete() error {
}

func (a *Client) delete(cache *AWS) error {
var err error
// Delete the EC2 instance
terminateInstancesInput := &ec2.TerminateInstancesInput{
InstanceIds: []string{cache.Instanceid},
}
_, err := a.ec2.TerminateInstances(context.Background(), terminateInstancesInput)
if err != nil {
return fmt.Errorf("error deleting instance: %v", err)
}

a.log.Wg.Add(1)
go a.log.Loading("Waiting for instance %s to be terminated\n", cache.Instanceid)

waiterOptions := []func(*ec2.InstanceTerminatedWaiterOptions){
func(o *ec2.InstanceTerminatedWaiterOptions) {
o.MaxDelay = 1 * time.Minute
o.MinDelay = 5 * time.Second
},
}
wait := ec2.NewInstanceTerminatedWaiter(a.ec2, waiterOptions...)
if err := wait.Wait(context.Background(), &ec2.DescribeInstancesInput{
InstanceIds: []string{cache.Instanceid},
}, 5*time.Minute, waiterOptions...); err != nil {
a.fail()
return fmt.Errorf("error waiting for instance to be terminated: %v", err)
}

// Delete the security group
deleteSecurityGroup := &ec2.DeleteSecurityGroupInput{
GroupId: &cache.SecurityGroupid,
}
_, err = a.ec2.DeleteSecurityGroup(context.Background(), deleteSecurityGroup)
if err != nil {
a.fail()
return fmt.Errorf("error deleting security group: %v", err)
if cache.Instanceid == "" {
a.log.Warning("No instance found to delete")
} else {
terminateInstancesInput := &ec2.TerminateInstancesInput{
InstanceIds: []string{cache.Instanceid},
}
_, err := a.ec2.TerminateInstances(context.Background(), terminateInstancesInput)
if err != nil {
return fmt.Errorf("error deleting instance: %v", err)
}

a.log.Wg.Add(1)
go a.log.Loading("Waiting for instance %s to be terminated\n", cache.Instanceid)

waiterOptions := []func(*ec2.InstanceTerminatedWaiterOptions){
func(o *ec2.InstanceTerminatedWaiterOptions) {
o.MaxDelay = 1 * time.Minute
o.MinDelay = 5 * time.Second
},
}
wait := ec2.NewInstanceTerminatedWaiter(a.ec2, waiterOptions...)
if err := wait.Wait(context.Background(), &ec2.DescribeInstancesInput{
InstanceIds: []string{cache.Instanceid},
}, 5*time.Minute, waiterOptions...); err != nil {
a.fail()
return fmt.Errorf("error waiting for instance to be terminated: %v", err)
}

// Delete the security group
deleteSecurityGroup := &ec2.DeleteSecurityGroupInput{
GroupId: &cache.SecurityGroupid,
}
_, err = a.ec2.DeleteSecurityGroup(context.Background(), deleteSecurityGroup)
if err != nil {
a.fail()
return fmt.Errorf("error deleting security group: %v", err)
}
}

// Delete the subnet
Expand Down
1 change: 1 addition & 0 deletions pkg/provisioner/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func buildDependencyGraph(env v1alpha1.Environment) ([]ProvisionFunc, error) {
for _, f := range graph["kubeadm"] {
ordered = append(ordered, functions[f])
}
ordered = append(ordered, functions["kubeadm"])
return ordered, nil
case "kind":
return []ProvisionFunc{docker, containerToolkit, nvdriver, kind}, nil
Expand Down
4 changes: 4 additions & 0 deletions pkg/provisioner/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func (p *Provisioner) Run(env v1alpha1.Environment) error {
}
}

if env.Spec.Kubernetes.KubernetesInstaller == "kubeadm" {
env.Spec.Kubernetes.K8sEndpointHost = p.HostUrl
}

for _, node := range graph {
// Add script header and common functions to the script
if err := addScriptHeader(&p.tpl); err != nil {
Expand Down
20 changes: 9 additions & 11 deletions pkg/provisioner/templates/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ const containerdTemplate = `
: ${CONTAINERD_VERSION:={{.Version}}}
# Install required packages
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg -y
with_retry 3 10s sudo apt-get update
install_packages_with_retry ca-certificates curl gnupg -y
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
Expand All @@ -40,7 +40,7 @@ echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
with_retry 3 10s sudo apt-get update
# Install containerd
install_packages_with_retry containerd.io=${CONTAINERD_VERSION}-1
Expand All @@ -64,23 +64,21 @@ type Containerd struct {
func NewContainerd(env v1alpha1.Environment) *Containerd {
var version string

if env.Spec.ContainerRuntime.Version != "" {
if strings.HasPrefix(env.Spec.ContainerRuntime.Version, "v") {
version = strings.TrimPrefix(env.Spec.ContainerRuntime.Version, "v")
} else {
version = env.Spec.ContainerRuntime.Version
}
} else {
if env.Spec.ContainerRuntime.Version == "" {
version = "1.6.27"
} else {
// remove the 'v' prefix from the version if it exists
version = strings.TrimPrefix(env.Spec.ContainerRuntime.Version, "v")
}

return &Containerd{
Version: version,
}
}

func (t *Containerd) Execute(tpl *bytes.Buffer, env v1alpha1.Environment) error {
containerdTemplate := template.Must(template.New("containerd").Parse(containerdTemplate))
err := containerdTemplate.Execute(tpl, &Containerd{Version: env.Spec.ContainerRuntime.Version})
err := containerdTemplate.Execute(tpl, &Containerd{Version: t.Version})
if err != nil {
return fmt.Errorf("failed to execute containerd template: %v", err)
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/provisioner/templates/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ type Kubernetes struct {
CalicoVersion string
CrictlVersion string
K8sEndpointHost string
KubeAdmnFeatureGates string
K8sFeatureGates string
// Kind exclusive
KindConfig string
}
Expand Down Expand Up @@ -218,6 +218,9 @@ func NewKubernetes(env v1alpha1.Environment) (*Kubernetes, error) {
if env.Spec.Kubernetes.K8sEndpointHost != "" {
kubernetes.K8sEndpointHost = env.Spec.Kubernetes.K8sEndpointHost
}
if env.Spec.Kubernetes.K8sFeatureGates != nil {
kubernetes.K8sFeatureGates = strings.Join(env.Spec.Kubernetes.K8sFeatureGates, ",")
}
if env.Spec.Kubernetes.KindConfig != "" {
kubernetes.KindConfig = env.Spec.Kubernetes.KindConfig
}
Expand Down

0 comments on commit 9c212e1

Please sign in to comment.