...
1
16
17 package util
18
19 import (
20 "fmt"
21
22 v1 "k8s.io/api/core/v1"
23 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24 "k8s.io/kubernetes/pkg/util/filesystem"
25 )
26
27
28
29 func FromApiserverCache(opts *metav1.GetOptions) {
30 opts.ResourceVersion = "0"
31 }
32
33 var IsUnixDomainSocket = filesystem.IsUnixDomainSocket
34
35
36 func GetNodenameForKernel(hostname string, hostDomainName string, setHostnameAsFQDN *bool) (string, error) {
37 kernelHostname := hostname
38
39 const fqdnMaxLen = 64
40 if len(hostDomainName) > 0 && setHostnameAsFQDN != nil && *setHostnameAsFQDN {
41 fqdn := fmt.Sprintf("%s.%s", hostname, hostDomainName)
42
43 if len(fqdn) > fqdnMaxLen {
44 return "", fmt.Errorf("failed to construct FQDN from pod hostname and cluster domain, FQDN %s is too long (%d characters is the max, %d characters requested)", fqdn, fqdnMaxLen, len(fqdn))
45 }
46 kernelHostname = fqdn
47 }
48 return kernelHostname, nil
49 }
50
51
52
53
54 func GetContainerByIndex(containers []v1.Container, statuses []v1.ContainerStatus, idx int) (v1.Container, bool) {
55 if idx < 0 || idx >= len(containers) || idx >= len(statuses) {
56 return v1.Container{}, false
57 }
58 if statuses[idx].Name != containers[idx].Name {
59 return v1.Container{}, false
60 }
61 return containers[idx], true
62 }
63
View as plain text