Skip to content

Commit

Permalink
[misc] OSSM-870 Fix ApplyServiceMeshCRDs function (maistra#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgn authored and luksa committed Feb 17, 2022
1 parent 6aa702a commit 938f653
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
17 changes: 4 additions & 13 deletions bin/update_maistra_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,16 @@ go get -d "maistra.io/api@${UPDATE_BRANCH}"
go mod tidy
go mod vendor

# Copy CRD's
dir=$(mktemp -d)
git clone "https://github.com/maistra/api.git" "${dir}"
pushd "${dir}"
git checkout "${UPDATE_BRANCH}"
popd

# FIXME: https://issues.redhat.com/browse/MAISTRA-2353
# For now we are just copying the files that already exist in istio, i.e., we are not adding any new files.
# We should copy all CRD's from api repo, i.e., uncomment the lines below and delete the other copy commands
# rm -f manifests/charts/base/crds/maistra*
# cp "${dir}"/manifests/* manifests/charts/base/crds

cp "${dir}"/manifests/federation.maistra.io_servicemeshpeers.yaml manifests/charts/base/crds
cp "${dir}"/manifests/federation.maistra.io_exportedservicesets.yaml manifests/charts/base/crds
cp "${dir}"/manifests/federation.maistra.io_importedservicesets.yaml manifests/charts/base/crds
cp "${dir}"/manifests/maistra.io_servicemeshextensions.yaml manifests/charts/base/crds

rm -rf "${dir}"
cp ./vendor/maistra.io/api/manifests/federation.maistra.io_servicemeshpeers.yaml manifests/charts/base/crds
cp ./vendor/maistra.io/api/manifests/federation.maistra.io_exportedservicesets.yaml manifests/charts/base/crds
cp ./vendor/maistra.io/api/manifests/federation.maistra.io_importedservicesets.yaml manifests/charts/base/crds
cp ./vendor/maistra.io/api/manifests/maistra.io_servicemeshextensions.yaml manifests/charts/base/crds

# Regenerate files
make clean gen
26 changes: 23 additions & 3 deletions tests/integration/servicemesh/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ import (
"fmt"
"io/ioutil"
"math/rand"
"path"
"strings"
"time"

v1 "k8s.io/api/core/v1"
apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"

// import maistra CRD manifests
_ "maistra.io/api/manifests"
"sigs.k8s.io/yaml"

"istio.io/istio/pkg/test/env"
"istio.io/istio/pkg/test/framework"
Expand All @@ -53,8 +57,24 @@ func ApplyServiceMeshCRDs(ctx resource.Context) (err error) {
return fmt.Errorf("cannot read maistra CRD YAMLs: %s", err)
}
for _, cluster := range ctx.Clusters().Kube().Primaries() {
if err = cluster.ApplyYAMLFiles("", crds...); err != nil {
return err
for _, crd := range crds {
// we need to manually Create() the CRD because Apply() wants to write its content into an annotation which fails because of size limitations
rawYAML, err := ioutil.ReadFile(crd)
if err != nil {
return err
}
rawJSON, err := yaml.YAMLToJSON(rawYAML)
if err != nil {
return err
}
crd := apiextv1.CustomResourceDefinition{}
_, _, err = unstructured.UnstructuredJSONScheme.Decode(rawJSON, nil, &crd)
if err != nil {
return err
}
if _, err := cluster.Ext().ApiextensionsV1().CustomResourceDefinitions().Create(context.TODO(), &crd, metav1.CreateOptions{}); err != nil {
return err
}
}
}
return err
Expand All @@ -68,7 +88,7 @@ func findCRDs() (list []string, err error) {
}
for _, file := range files {
if !file.IsDir() && strings.HasSuffix(file.Name(), ".yaml") {
list = append(list, file.Name())
list = append(list, path.Join(manifestsDir, file.Name()))
}
}
return
Expand Down

0 comments on commit 938f653

Please sign in to comment.