Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable pod VM image selection via pod annotation #2155

Merged
merged 8 commits into from
Nov 17, 2024
7 changes: 7 additions & 0 deletions src/cloud-api-adaptor/test/e2e/aws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,10 @@ func TestAwsCreateNginxDeployment(t *testing.T) {
assert := NewAWSAssert()
DoTestNginxDeployment(t, testEnv, assert)
}

func TestAwsCreatePeerPodContainerWithInvalidAlternateImage(t *testing.T) {
assert := NewAWSAssert()
nonExistingImageName := "ami-123456"
expectedErrorMessage := "InvalidAMIID.NotFound: The image id '[ami-1234567]' does not exist: not found"
DoTestCreatePeerPodContainerWithInvalidAlternateImage(t, testEnv, assert, nonExistingImageName, expectedErrorMessage)
}
6 changes: 3 additions & 3 deletions src/cloud-api-adaptor/test/e2e/common_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,12 @@ func DoTestCreatePeerPodContainerWithValidAlternateImage(t *testing.T, e env.Env
NewTestCase(t, e, "PodVMwithAnnotationsValidAlternateImage", assert, "PodVM created with an alternate image").WithPod(pod).WithAlternateImage(alternateImageName).Run()
}

func DoTestCreatePeerPodContainerWithInvalidAlternateImage(t *testing.T, e env.Environment, assert CloudAssert) {
func DoTestCreatePeerPodContainerWithInvalidAlternateImage(t *testing.T, e env.Environment, assert CloudAssert,
nonExistingImageName, expectedErrorMessage string) {

podName := "annotations-invalid-alternate-image"
containerName := "busybox"
imageName := getBusyboxTestImage(t)
nonExistingImageName := "non-existing-image"
expectedErrorMessage := "Error in creating volume: Can't retrieve volume " + nonExistingImageName
annotationData := map[string]string{
"io.katacontainers.config.hypervisor.image": nonExistingImageName,
}
Expand Down
4 changes: 3 additions & 1 deletion src/cloud-api-adaptor/test/e2e/libvirt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ func TestLibvirtCreatePeerPodContainerWithValidAlternateImage(t *testing.T) {

func TestLibvirtCreatePeerPodContainerWithInvalidAlternateImage(t *testing.T) {
assert := LibvirtAssert{}
DoTestCreatePeerPodContainerWithInvalidAlternateImage(t, testEnv, assert)
nonExistingImageName := "non-existing-image"
expectedErrorMessage := "Error in creating volume: Can't retrieve volume " + nonExistingImageName
DoTestCreatePeerPodContainerWithInvalidAlternateImage(t, testEnv, assert, nonExistingImageName, expectedErrorMessage)
}

func TestLibvirtCreatePeerPodWithJob(t *testing.T) {
Expand Down
6 changes: 6 additions & 0 deletions src/cloud-providers/aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ func (p *awsProvider) CreateInstance(ctx context.Context, podName, sandboxID str
TagSpecifications: tagSpecifications,
}
} else {

if spec.Image != "" {
logger.Printf("Choosing %s from annotation as the AWS AMI for the PodVM image", spec.Image)
p.serviceConfig.ImageId = spec.Image
}

input = &ec2.RunInstancesInput{
MinCount: aws.Int32(1),
MaxCount: aws.Int32(1),
Expand Down
5 changes: 5 additions & 0 deletions src/cloud-providers/azure/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ func (p *azureProvider) CreateInstance(ctx context.Context, podName, sandboxID s
return nil, err
}

if spec.Image != "" {
logger.Printf("Choosing %s from annotation as the Azure Image for the PodVM image", spec.Image)
p.serviceConfig.ImageId = spec.Image
}

vmParameters, err := p.getVMParameters(instanceSize, diskName, cloudConfigData, sshBytes, instanceName, nicName)
if err != nil {
return nil, err
Expand Down
5 changes: 5 additions & 0 deletions src/cloud-providers/docker/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ func (p *dockerProvider) CreateInstance(ctx context.Context, podName, sandboxID
volumeBinding = append(volumeBinding, fmt.Sprintf("%s:%s",
filepath.Join(p.DataDir, "kata-containers"), "/run/kata-containers"))

if spec.Image != "" {
logger.Printf("Choosing %s from annotation as the docker image for the PodVM image", spec.Image)
p.PodVMDockerImage = spec.Image
}

// (host)image dir -> (container) /image
// There is a podvm systemd service in pod which bind mounts /run/image to /image
volumeBinding = append(volumeBinding, fmt.Sprintf("%s:%s",
Expand Down
10 changes: 9 additions & 1 deletion src/cloud-providers/gcp/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ func (p *gcpProvider) CreateInstance(ctx context.Context, podName, sandboxID str
userDataEnc := base64.StdEncoding.EncodeToString([]byte(userData))
logger.Printf("userDataEnc: %s", userDataEnc)

// It's expected that the image from the annotation will follow the format "projects/<project>/global/images/<image>"
srcImage := proto.String(fmt.Sprintf("projects/%s/global/images/%s", p.serviceConfig.ProjectId, p.serviceConfig.ImageName))

if spec.Image != "" {
logger.Printf("Choosing %s from annotation as the GCP image for the PodVM image", spec.Image)
srcImage = proto.String(spec.Image)
}

insertReq := &computepb.InsertInstanceRequest{
Project: p.serviceConfig.ProjectId,
Zone: p.serviceConfig.Zone,
Expand All @@ -98,7 +106,7 @@ func (p *gcpProvider) CreateInstance(ctx context.Context, podName, sandboxID str
{
InitializeParams: &computepb.AttachedDiskInitializeParams{
DiskSizeGb: proto.Int64(20),
SourceImage: proto.String(fmt.Sprintf("projects/%s/global/images/%s", p.serviceConfig.ProjectId, p.serviceConfig.ImageName)),
SourceImage: srcImage,
DiskType: proto.String(fmt.Sprintf("zones/%s/diskTypes/pd-standard", p.serviceConfig.Zone)),
},
AutoDelete: proto.Bool(true),
Expand Down
4 changes: 2 additions & 2 deletions src/cloud-providers/ibmcloud-powervs/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (_ *Manager) ParseCmd(flags *flag.FlagSet) {
flags.StringVar(&ibmcloudPowerVSConfig.Zone, "zone", "", "PowerVS zone name")
flags.StringVar(&ibmcloudPowerVSConfig.ServiceInstanceID, "service-instance-id", "", "ID of the PowerVS Service Instance")
flags.StringVar(&ibmcloudPowerVSConfig.NetworkID, "network-id", "", "ID of the network instance")
flags.StringVar(&ibmcloudPowerVSConfig.ImageID, "image-id", "", "ID of the boot image")
flags.StringVar(&ibmcloudPowerVSConfig.ImageId, "image-id", "", "ID of the boot image")
flags.StringVar(&ibmcloudPowerVSConfig.SSHKey, "ssh-key", "", "Name of the SSH Key")
flags.Float64Var(&ibmcloudPowerVSConfig.Memory, "memory", 2, "Amount of memory in GB")
flags.Float64Var(&ibmcloudPowerVSConfig.Processors, "cpu", 0.5, "Number of processors allocated")
Expand All @@ -41,7 +41,7 @@ func (_ *Manager) LoadEnv() {
provider.DefaultToEnv(&ibmcloudPowerVSConfig.Zone, "POWERVS_ZONE", "")
provider.DefaultToEnv(&ibmcloudPowerVSConfig.ServiceInstanceID, "POWERVS_SERVICE_INSTANCE_ID", "")
provider.DefaultToEnv(&ibmcloudPowerVSConfig.NetworkID, "POWERVS_NETWORK_ID", "")
provider.DefaultToEnv(&ibmcloudPowerVSConfig.ImageID, "POWERVS_IMAGE_ID", "")
provider.DefaultToEnv(&ibmcloudPowerVSConfig.ImageId, "POWERVS_IMAGE_ID", "")
provider.DefaultToEnv(&ibmcloudPowerVSConfig.SSHKey, "POWERVS_SSH_KEY_NAME", "")
provider.DefaultToEnv(&ibmcloudPowerVSConfig.ProcessorType, "POWERVS_PROCESSOR_TYPE", "")
provider.DefaultToEnv(&ibmcloudPowerVSConfig.SystemType, "POWERVS_SYSTEM_TYPE", "")
Expand Down
9 changes: 7 additions & 2 deletions src/cloud-providers/ibmcloud-powervs/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ func (p *ibmcloudPowerVSProvider) CreateInstance(ctx context.Context, podName, s
return nil, err
}

if spec.Image != "" {
logger.Printf("Choosing %s from annotation as the Power VS image for the PodVM image", spec.Image)
p.serviceConfig.ImageId = spec.Image
}

body := &models.PVMInstanceCreate{
ServerName: &instanceName,
ImageID: &p.serviceConfig.ImageID,
ImageID: &p.serviceConfig.ImageId,
KeyPairName: p.serviceConfig.SSHKey,
Networks: []*models.PVMInstanceAddNetwork{
{
Expand Down Expand Up @@ -143,7 +148,7 @@ func (p *ibmcloudPowerVSProvider) Teardown() error {
}

func (p *ibmcloudPowerVSProvider) ConfigVerifier() error {
ImageId := p.serviceConfig.ImageID
ImageId := p.serviceConfig.ImageId
if len(ImageId) == 0 {
return fmt.Errorf("ImageId is empty")
}
Expand Down
2 changes: 1 addition & 1 deletion src/cloud-providers/ibmcloud-powervs/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type Config struct {
Zone string
ServiceInstanceID string
NetworkID string
ImageID string
ImageId string
SSHKey string
Memory float64
Processors float64
Expand Down
Loading