-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Scorecard2 pod execution #2890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scorecard2 pod execution #2890
Changes from 76 commits
32087a9
45c3d34
857e056
2e6db59
958e2ae
6a971a4
43555bb
db2d6e5
d861b3d
f009ea8
87ad36d
3658568
50981f6
474641b
467c2ae
7ebf414
295bb5d
0abefbb
f7e6e13
7f0cb6d
13d04fe
457046f
e3f2b41
606aa16
34a411b
3356aa5
ec7800e
b59aa81
99ad3fb
300ee72
f98e8f4
cb322e4
d7c98ab
0bf89cd
9464b84
38cc7af
fe64d30
28224bf
b92ee61
770f91c
0dc37a9
a4f8884
2405569
a13becc
d6e7087
ba955d3
f894e11
4a0baa0
9d4cc1d
ae9d02d
61c1108
8d21ee3
98cfa69
67b7518
521ae4d
c1fdf82
61a6344
6a41299
a761a26
b9cebae
2137885
1329a4a
d457c0e
b44503a
49c3ad7
54818cc
b67d4ae
4efa124
04b2dbc
cc62112
5aa6bdc
7c02717
660dd7c
c06c512
fffa03a
8dc43b6
c3075df
397c11f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,11 +17,14 @@ package main | |
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
|
||
"github.com/operator-framework/operator-sdk/pkg/apis/scorecard/v1alpha2" | ||
scapiv1alpha2 "github.com/operator-framework/operator-sdk/pkg/apis/scorecard/v1alpha2" | ||
|
||
"github.com/operator-framework/operator-sdk/internal/scorecard/alpha" | ||
"github.com/operator-framework/operator-sdk/internal/scorecard/alpha/tests" | ||
) | ||
|
||
|
@@ -35,7 +38,8 @@ import ( | |
// test image. | ||
|
||
const ( | ||
bundlePath = "/scorecard" | ||
// bundleTar is the tar file containing the bundle contents | ||
bundleTar = "/scorecard/bundle.tar" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. I'm assuming you resorted to using a tar file because it isn't possible to create a single configmap from a directory recursively. However this approach is a little problematic because it would require every custom image implementation to untar the bundle before using it, which isn't the best. We need to think about this a little bit. Other options include:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, I could see using an initcontainer for this purpose. also, gzipping this file would be good to do too. |
||
) | ||
|
||
func main() { | ||
|
@@ -44,7 +48,19 @@ func main() { | |
log.Fatal("test name argument is required") | ||
} | ||
|
||
cfg, err := tests.GetBundle(bundlePath) | ||
// Create tmp directory for the untar'd bundle | ||
tmpDir, err := ioutil.TempDir("/tmp", "scorecard-bundle") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer os.Remove(tmpDir) | ||
|
||
err = alpha.UntarFile(bundleTar, tmpDir) | ||
if err != nil { | ||
log.Fatalf("error untarring bundle %s", err.Error()) | ||
} | ||
|
||
cfg, err := tests.GetBundle(tmpDir) | ||
if err != nil { | ||
log.Fatal(err.Error()) | ||
} | ||
|
@@ -62,14 +78,10 @@ func main() { | |
result = tests.SpecDescriptorsTest(cfg) | ||
case tests.OLMStatusDescriptorsTest: | ||
result = tests.StatusDescriptorsTest(cfg) | ||
case tests.BasicCheckStatusTest: | ||
result = tests.CheckStatusTest(cfg) | ||
case tests.BasicCheckSpecTest: | ||
result = tests.CheckSpecTest(cfg) | ||
default: | ||
log.Fatal("invalid test name argument passed") | ||
// TODO print out full list of test names to give a hint | ||
// to the end user on what the valid tests are | ||
result = printValidTests() | ||
} | ||
|
||
prettyJSON, err := json.MarshalIndent(result, "", " ") | ||
|
@@ -79,3 +91,20 @@ func main() { | |
fmt.Printf("%s\n", string(prettyJSON)) | ||
|
||
} | ||
|
||
// printValidTests will print out full list of test names to give a hint to the end user on what the valid tests are | ||
func printValidTests() (result v1alpha2.ScorecardTestResult) { | ||
camilamacedo86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
result.State = scapiv1alpha2.FailState | ||
result.Errors = make([]string, 0) | ||
result.Suggestions = make([]string, 0) | ||
|
||
str := fmt.Sprintf("Valid tests for this image include: %s, %s, %s, %s, %s, %s", | ||
tests.OLMBundleValidationTest, | ||
tests.OLMCRDsHaveValidationTest, | ||
tests.OLMCRDsHaveResourcesTest, | ||
tests.OLMSpecDescriptorsTest, | ||
tests.OLMStatusDescriptorsTest, | ||
tests.BasicCheckSpecTest) | ||
result.Errors = append(result.Errors, str) | ||
return result | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2020 The Operator-SDK Authors | ||
// | ||
// 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 alpha | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
|
||
"k8s.io/apimachinery/pkg/util/rand" | ||
) | ||
|
||
// getBundleData tars up the contents of a bundle from a path, and returns that tar file in []byte | ||
func getBundleData(bundlePath string) (bundleData []byte, err error) { | ||
|
||
// make sure the bundle exists on disk | ||
_, err = os.Stat(bundlePath) | ||
if os.IsNotExist(err) { | ||
return bundleData, fmt.Errorf("bundle path is not valid %w", err) | ||
} | ||
|
||
tempTarFileName := fmt.Sprintf("%s%ctempBundle-%s.tar", os.TempDir(), os.PathSeparator, rand.String(4)) | ||
|
||
paths := []string{bundlePath} | ||
err = CreateTarFile(tempTarFileName, paths) | ||
if err != nil { | ||
return bundleData, fmt.Errorf("error creating tar of bundle %w", err) | ||
} | ||
|
||
defer os.Remove(tempTarFileName) | ||
|
||
var buf []byte | ||
buf, err = ioutil.ReadFile(tempTarFileName) | ||
if err != nil { | ||
return bundleData, fmt.Errorf("error reading tar of bundle %w", err) | ||
} | ||
|
||
return buf, err | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,11 +30,12 @@ func TestInvalidConfigPath(t *testing.T) { | |
for _, c := range cases { | ||
t.Run(c.configPathValue, func(t *testing.T) { | ||
_, err := LoadConfig(c.configPathValue) | ||
if err != nil && c.wantError { | ||
t.Logf("Wanted error and got error : %v", err) | ||
return | ||
} else if err != nil && !c.wantError { | ||
t.Errorf("Wanted result but got error: %v", err) | ||
if err == nil && c.wantError { | ||
t.Fatalf("Wanted error but got no error") | ||
} else if err != nil { | ||
if !c.wantError { | ||
t.Fatalf("Wanted result but got error: %v", err) | ||
} | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WDYT about the default one:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, not sure, for some reason that syntax I find hard to read. I'll think about it however. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am ok if you would prefer this way 👍 all fine .. just to clarifies .. it is that I found a little weird since usually, we see something as : func TestAbs(t *testing.T) {
got := Abs(-1)
if got != 1 {
t.Errorf("Abs(-1) = %d; want 1", got)
}
} |
||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does
client-go
orcontroller-runtime
have a function we can use to get the client? It doesn't seem like something that should be in the scorecard package.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I found that the controller-runtime has a GetConfig(), I've updated the code to use that since it was used in the 'operator-sdk new' command. I found that to support a --kubeconfig cobra flag with this library that I had to set the KUBECONFIG env var if --kubeconfig is specified. I found an example of that in cmd/operator-sdk/run/local.go.