github.com/mirantis/virtlet@v1.5.2-0.20191204181327-1659b8a48e9b/pkg/metadata/fake/fake.go (about)

     1  /*
     2  Copyright 2018 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 fake
    18  
    19  import (
    20  	"strconv"
    21  
    22  	"github.com/Mirantis/virtlet/pkg/metadata/types"
    23  	"github.com/Mirantis/virtlet/pkg/utils"
    24  )
    25  
    26  const (
    27  	samplePodNsUUID       = "cd6bc1b7-a9e2-4739-ade9-3e2447d28a90"
    28  	sampleContainerNsUUID = "a51f5bed-db9c-49b1-a1b6-9989d46d637b"
    29  )
    30  
    31  // ContainerTestConfig specifies configuration for a container test.
    32  type ContainerTestConfig struct {
    33  	// Container name.
    34  	Name string
    35  	// Pod sandbox id.
    36  	SandboxID string
    37  	// Container id.
    38  	ContainerID string
    39  	// Image reference.
    40  	Image string
    41  	// Container labels.
    42  	Labels map[string]string
    43  	// Container annotations.
    44  	Annotations map[string]string
    45  }
    46  
    47  // GetSandboxes returns the specified number of PodSandboxConfig
    48  // objects with "fake" contents.
    49  func GetSandboxes(sandboxCount int) []*types.PodSandboxConfig {
    50  	sandboxes := []*types.PodSandboxConfig{}
    51  	for i := 0; i < sandboxCount; i++ {
    52  		name := "testName_" + strconv.Itoa(i)
    53  		sandboxConfig := &types.PodSandboxConfig{
    54  			Name:         name,
    55  			Uid:          utils.NewUUID5(samplePodNsUUID, name),
    56  			Namespace:    "default",
    57  			Attempt:      uint32(0),
    58  			Hostname:     "localhost",
    59  			LogDirectory: "/var/log/test_log_directory",
    60  			Labels: map[string]string{
    61  				"foo":  "bar",
    62  				"fizz": "buzz",
    63  			},
    64  			Annotations: map[string]string{
    65  				"hello": "world",
    66  				"virt":  "let",
    67  			},
    68  		}
    69  
    70  		sandboxes = append(sandboxes, sandboxConfig)
    71  	}
    72  
    73  	return sandboxes
    74  }
    75  
    76  // GetContainersConfig returns the specified number of
    77  // ContainerTestConfig objects.
    78  func GetContainersConfig(sandboxConfigs []*types.PodSandboxConfig) []*ContainerTestConfig {
    79  	containers := []*ContainerTestConfig{}
    80  	for _, sandbox := range sandboxConfigs {
    81  		name := "container-for-" + sandbox.Name
    82  		containerConf := &ContainerTestConfig{
    83  			Name:        name,
    84  			SandboxID:   sandbox.Uid,
    85  			Image:       "testImage",
    86  			ContainerID: utils.NewUUID5(sampleContainerNsUUID, name),
    87  			Labels:      map[string]string{"foo": "bar", "fizz": "buzz"},
    88  			Annotations: map[string]string{"hello": "world", "virt": "let"},
    89  		}
    90  		containers = append(containers, containerConf)
    91  	}
    92  
    93  	return containers
    94  }