forked from operator-framework/rukpak
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes operator-framework#167 Signed-off-by: Austin Macdonald <austin@redhat.com>
- Loading branch information
Showing
6 changed files
with
125 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# TODO(asmacdo) dev only, remove before merge | ||
apiVersion: core.rukpak.io/v1alpha1 | ||
kind: BundleDeployment | ||
metadata: | ||
name: combo | ||
spec: | ||
provisionerClassName: core.rukpak.io/plain | ||
template: | ||
metadata: | ||
labels: | ||
app: combo | ||
spec: | ||
provisionerClassName: core.rukpak.io/plain | ||
source: | ||
image: | ||
ref: quay.io/operator-framework/combo-bundle:v0.0.2 | ||
type: image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package validators | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"io/fs" | ||
"path/filepath" | ||
|
||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
apimachyaml "k8s.io/apimachinery/pkg/util/yaml" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
type Validator interface { | ||
Validate(fs.FS) error | ||
} | ||
|
||
// TODO(asmacdo) I moved this *and* made it public, is this a problem? | ||
func GetObjects(bundleFS fs.FS) ([]client.Object, error) { | ||
var objects []client.Object | ||
const manifestsDir = "manifests" | ||
|
||
entries, err := fs.ReadDir(bundleFS, manifestsDir) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, e := range entries { | ||
if e.IsDir() { | ||
return nil, fmt.Errorf("subdirectories are not allowed within the %q directory of the bundle image filesystem: found %q", manifestsDir, filepath.Join(manifestsDir, e.Name())) | ||
} | ||
fileData, err := fs.ReadFile(bundleFS, filepath.Join(manifestsDir, e.Name())) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
dec := apimachyaml.NewYAMLOrJSONDecoder(bytes.NewReader(fileData), 1024) | ||
for { | ||
obj := unstructured.Unstructured{} | ||
err := dec.Decode(&obj) | ||
if errors.Is(err, io.EOF) { | ||
break | ||
} | ||
if err != nil { | ||
// TODO(asmacdo) is this clear enough? | ||
return nil, fmt.Errorf("read %q: %v", e.Name(), err) | ||
} | ||
objects = append(objects, &obj) | ||
} | ||
} | ||
return objects, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package validators | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"io/fs" | ||
) | ||
|
||
func NewPlainValidator() (Validator, error) { | ||
|
||
return &plainValidator{}, nil | ||
} | ||
|
||
type plainValidator struct { | ||
} | ||
|
||
func (r *plainValidator) Validate(bundle fs.FS) error { | ||
var validationErrors []error | ||
objects, err := GetObjects(bundle) | ||
if err != nil { | ||
validationErrors = append(validationErrors, fmt.Errorf("get objects from bundle manifests: %v", err)) | ||
} | ||
if len(objects) == 0 { | ||
validationErrors = append(validationErrors, errors.New("invalid bundle: found zero objects: "+ | ||
"plain+v0 bundles are required to contain at least one object")) | ||
} | ||
|
||
// TODO(asmacdo) dev only, remove before merge | ||
validationErrors = append(validationErrors, errors.New("")) | ||
validationErrors = append(validationErrors, errors.New("hello")) | ||
validationErrors = append(validationErrors, errors.New("world")) | ||
validationErrors = append(validationErrors, errors.New("annnndd")) | ||
validationErrors = append(validationErrors, errors.New("four Errors!")) | ||
validationErrors = append(validationErrors, errors.New("moved this shit around!")) | ||
|
||
err = errors.New("") | ||
for _, each := range validationErrors { | ||
err = fmt.Errorf("%v\n%v", err, each) | ||
} | ||
return err | ||
} |