1/*
2Copyright 2016 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package testing
18
19import (
20	"fmt"
21
22	runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
23)
24
25// BuildContainerName creates a unique container name string.
26func BuildContainerName(metadata *runtimeapi.ContainerMetadata, sandboxID string) string {
27	// include the sandbox ID to make the container ID unique.
28	return fmt.Sprintf("%s_%s_%d", sandboxID, metadata.Name, metadata.Attempt)
29}
30
31// BuildSandboxName creates a unique sandbox name string.
32func BuildSandboxName(metadata *runtimeapi.PodSandboxMetadata) string {
33	return fmt.Sprintf("%s_%s_%s_%d", metadata.Name, metadata.Namespace, metadata.Uid, metadata.Attempt)
34}
35
36func filterInLabels(filter, labels map[string]string) bool {
37	for k, v := range filter {
38		if value, ok := labels[k]; ok {
39			if value != v {
40				return false
41			}
42		} else {
43			return false
44		}
45	}
46
47	return true
48}
49