github.com/equinix-metal/virtlet@v1.5.2-0.20191204181327-1659b8a48e9b/tests/e2e/image_name_translation_test.go (about)

     1  /*
     2  Copyright 2017 Mirantis
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package e2e
    18  
    19  import (
    20  	"regexp"
    21  	"time"
    22  
    23  	. "github.com/onsi/gomega"
    24  	meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    25  
    26  	virtlet_v1 "github.com/Mirantis/virtlet/pkg/api/virtlet.k8s/v1"
    27  	. "github.com/Mirantis/virtlet/tests/e2e/ginkgo-ext"
    28  )
    29  
    30  var _ = Describe("Image URL", func() {
    31  	var vimName, digestSuffix string
    32  
    33  	BeforeAll(func() {
    34  		re := regexp.MustCompile("^(.*?)(@.*)?$")
    35  		m := re.FindStringSubmatch(*vmImageLocation)
    36  		if m == nil {
    37  			panic("impossible regexp failure")
    38  		}
    39  		url := "https://" + m[1] // FIXME: this will only work if Virtlet uses https by default
    40  		digestSuffix = m[2]
    41  
    42  		vim, err := controller.CreateVirtletImageMapping(virtlet_v1.VirtletImageMapping{
    43  			ObjectMeta: meta_v1.ObjectMeta{
    44  				GenerateName: "virtlet-e2e-",
    45  			},
    46  			Spec: virtlet_v1.ImageTranslation{
    47  				Rules: []virtlet_v1.TranslationRule{
    48  					{
    49  						Name: "test-image",
    50  						URL:  url,
    51  					},
    52  				},
    53  			},
    54  		})
    55  
    56  		Expect(err).NotTo(HaveOccurred())
    57  		vimName = vim.Name
    58  	})
    59  
    60  	AfterAll(func() {
    61  		Expect(controller.DeleteVirtletImageMapping(vimName)).To(Succeed())
    62  	})
    63  
    64  	It("Can be specified in CRD [Conformance]", func() {
    65  		vm := controller.VM("cirros-vm-with-remapped-image")
    66  		Expect(vm.CreateAndWait(VMOptions{
    67  			Image: "test-image" + digestSuffix,
    68  		}.ApplyDefaults(), time.Minute*5, nil)).To(Succeed())
    69  		_, err := vm.Pod()
    70  		Expect(err).NotTo(HaveOccurred())
    71  		deleteVM(vm)
    72  	})
    73  })