Skip to content

Commit

Permalink
Merge pull request #215 from adambkaplan/strategies-manifestival
Browse files Browse the repository at this point in the history
Parse Build Strategies with Manifestival
  • Loading branch information
openshift-merge-bot[bot] authored Jun 5, 2024
2 parents db1f9a2 + 0b2c93d commit 5e455f3
Showing 1 changed file with 12 additions and 26 deletions.
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
}

0 comments on commit 5e455f3

Please sign in to comment.