Skip to content
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

Parse Build Strategies with Manifestival #215

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 12 additions & 26 deletions test/common.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
package test

import (
"bytes"
"context"
"io/fs"
"os"
"fmt"
"path/filepath"
"time"

"github.com/manifestival/manifestival"
o "github.com/onsi/gomega"

apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
k8syaml "k8s.io/apimachinery/pkg/util/yaml"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/shipwright-io/build/pkg/apis/build/v1alpha1"
"github.com/shipwright-io/operator/pkg/common"
)

Expand Down Expand Up @@ -108,29 +105,18 @@ func ParseBuildStrategyNames() ([]string, error) {
}
strategyPath := filepath.Join(koDataPath, "samples", "buildstrategy")
sampleNames := []string{}
err = filepath.WalkDir(strategyPath, func(path string, d fs.DirEntry, err error) error {
if d.IsDir() {
return nil
}
clusterBuildStrategy := &v1alpha1.ClusterBuildStrategy{}
decodeErr := decodeYaml(path, clusterBuildStrategy)
if decodeErr != nil {
return decodeErr
}
sampleNames = append(sampleNames, clusterBuildStrategy.Name)
return nil
})
manifest, err := manifestival.ManifestFrom(manifestival.Recursive(strategyPath))
if err != nil {
return nil, err
return sampleNames, err
}
return sampleNames, nil
}
for _, obj := range manifest.Resources() {
if obj.GetKind() == "ClusterBuildStrategy" {
sampleNames = append(sampleNames, obj.GetName())
}

func decodeYaml(path string, obj *v1alpha1.ClusterBuildStrategy) error {
yaml, err := os.ReadFile(path)
if err != nil {
return err
}
decoder := k8syaml.NewYAMLOrJSONDecoder(bytes.NewBuffer(yaml), 16)
return decoder.Decode(obj)
if len(sampleNames) == 0 {
return sampleNames, fmt.Errorf("no ClusterBuildStrategy objects found in %s", strategyPath)
}
return sampleNames, nil
}
Loading