Skip to content

Commit

Permalink
Add app ignores for different cluster types
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
  • Loading branch information
Vladimir Popov committed Feb 24, 2021
1 parent c33988f commit 7fda533
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 9 deletions.
36 changes: 36 additions & 0 deletions extensions/ctrpull/ignore.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2021 Doc.ai and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package ctrpull

var ignored map[string]struct{}

// SetClusterKind sets ignored for cluster type `kind`
func SetClusterKind() {
ignored = map[string]struct{}{
"forwarder-sriov": {},
"nsc-kernel-ponger": {},
"nsc-vfio": {},
"nse-vfio": {},
}
}

// SetClusterPacket sets ignored for cluster type `packet`
func SetClusterPacket() {
ignored = map[string]struct{}{
"registry-k8s": {},
}
}
2 changes: 1 addition & 1 deletion extensions/ctrpull/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ data:
for image in {{.TestImages}}; do
if ! ctr -n=k8s.io image ls -q | grep "\${image}"; then
ctr -n=k8s.io image pull "docker.io/\${image}"
ctr -n=k8s.io image pull "\${image}"
fi
done
EOF
Expand Down
74 changes: 66 additions & 8 deletions extensions/ctrpull/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ import (
"github.com/networkservicemesh/gotestmd/pkg/suites/shell"
)

var once sync.Once
const (
defaultDomain = "docker.io/"
defaultTag = ":latest"
)

// Suite creates `ctr-pull` daemonset which pulls all test images for all cluster nodes.
type Suite struct {
shell.Suite
Dir string
}

var once sync.Once

func (s *Suite) SetupSuite() {
once.Do(func() {
testImages, err := s.findTestImages()
Expand All @@ -61,13 +66,14 @@ func (s *Suite) SetupSuite() {
})
}

func (s *Suite) findTestImages() (testImages []string, err error) {
func (s *Suite) findTestImages() ([]string, error) {
imagePattern := regexp.MustCompile(".*image: (?P<image>.*)")
imageSubexpIndex := imagePattern.SubexpIndex("image")

err = filepath.Walk(filepath.Join(s.Dir, "apps"), func(path string, info os.FileInfo, err error) error {
if err != nil || info.IsDir() || !strings.HasSuffix(info.Name(), ".yaml") {
return err
var testImages []string
walkFunc := func(path string, info os.FileInfo, err error) error {
if ok, skipErr := s.shouldSkipWithError(info, err); ok {
return skipErr
}

file, err := os.Open(path)
Expand All @@ -79,12 +85,64 @@ func (s *Suite) findTestImages() (testImages []string, err error) {
for scanner.Scan() {
if imagePattern.MatchString(scanner.Text()) {
image := imagePattern.FindAllStringSubmatch(scanner.Text(), -1)[0][imageSubexpIndex]
testImages = append(testImages, image)
testImages = append(testImages, s.fullImageName(image))
}
}

return nil
})
}

if err := filepath.Walk(filepath.Join(s.Dir, "apps"), walkFunc); err != nil {
return nil, err
}
if err := filepath.Walk(filepath.Join(s.Dir, "examples", "spire"), walkFunc); err != nil {
return nil, err
}

return testImages, nil
}

func (s *Suite) shouldSkipWithError(info os.FileInfo, err error) (bool, error) {
if err != nil {
return true, err
}

if info.IsDir() {
if _, ok := ignored[info.Name()]; ok {
return true, filepath.SkipDir
}
return true, nil
}

if !strings.HasSuffix(info.Name(), ".yaml") {
return true, nil
}

return false, nil
}

return testImages, err
func (s *Suite) fullImageName(image string) string {
// domain/library/name:tag

split := strings.Split(image, "/")
switch len(split) {
case 3:
// nothing to do
case 2:
image = defaultDomain + image
default:
return ""
}

split = strings.Split(image, ":")
switch len(split) {
case 2:
// nothing to do
case 1:
image += defaultTag
default:
return ""
}

return image
}

0 comments on commit 7fda533

Please sign in to comment.