github.com/abayer/test-infra@v0.0.5/kubetest/dind/util.go (about) 1 /* 2 Copyright 2018 The Kubernetes Authors. 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 dind implements dind specific kubetest code. 18 package dind 19 20 import ( 21 "bufio" 22 "fmt" 23 "os" 24 "strings" 25 26 "k8s.io/test-infra/kubetest/util" 27 ) 28 29 // GetDockerVersion reads the stable-status.txt file from bazel to get the docker artifact version. 30 func GetDockerVersion() (string, error) { 31 fileName := util.K8s("kubernetes", "bazel-out", "stable-status.txt") 32 file, err := os.Open(fileName) 33 if err != nil { 34 return "", err 35 } 36 defer file.Close() 37 38 scanner := bufio.NewScanner(file) 39 for scanner.Scan() { 40 tokens := strings.Fields(scanner.Text()) 41 if len(tokens) < 2 { 42 continue 43 } 44 if tokens[0] != "STABLE_DOCKER_TAG" { 45 continue 46 } 47 return tokens[1], nil 48 } 49 50 if err = scanner.Err(); err != nil { 51 return "", err 52 } 53 return "", fmt.Errorf("docker tag not found in file %s", fileName) 54 }