Skip to content

Commit

Permalink
TEST ONLY
Browse files Browse the repository at this point in the history
  • Loading branch information
kylewuolle committed Sep 24, 2024
1 parent f0d08ff commit 8aed88f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
- name: Run E2E tests
env:
MANAGED_CLUSTER_NAME: ${{ steps.vars.outputs.clustername }}
REGISTRY_REPO: 'oci://ghcr.io/mirantis/hmc/charts-ci'
#REGISTRY_REPO: 'oci://ghcr.io/mirantis/hmc/charts-ci'
IMG: 'ghcr.io/mirantis/hmc/controller-ci:${{ steps.vars.outputs.version }}'
run: |
make test-e2e
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ var _ = Describe("controller", Ordered, func() {
Context("Operator", func() {
It("should run successfully", func() {
kc := kubeclient.NewFromLocal(namespace)
aws.CreateCredentialSecret(context.Background(), kc)

By("validating that the hmc-controller and capi provider controllers are running")
Eventually(func() error {
Expand All @@ -74,6 +73,8 @@ var _ = Describe("controller", Ordered, func() {
}
return nil
}).WithTimeout(15 * time.Minute).WithPolling(10 * time.Second).Should(Succeed())

aws.CreateCredentialSecret(context.Background(), kc)
})
})

Expand Down
69 changes: 63 additions & 6 deletions test/managedcluster/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,86 @@
package aws

import (
"bufio"
"bytes"
"context"
"encoding/json"
"os/exec"

corev1 "k8s.io/api/core/v1"

"errors"
"github.com/a8m/envsubst"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"io"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/runtime/serializer/yaml"
"k8s.io/apimachinery/pkg/types"
yamlutil "k8s.io/apimachinery/pkg/util/yaml"
"k8s.io/client-go/discovery"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/restmapper"
"os"

"github.com/Mirantis/hmc/test/kubeclient"
"github.com/Mirantis/hmc/test/managedcluster"
"github.com/Mirantis/hmc/test/utils"
)

func CreateCredentialSecret(ctx context.Context, kc *kubeclient.KubeClient) {
GinkgoHelper()
serializer := yaml.NewDecodingSerializer(unstructured.UnstructuredJSONScheme)
yamlFile, err := os.ReadFile("config/dev/aws-credentials.yaml")
Expect(err).NotTo(HaveOccurred())

yamlFile, err = envsubst.Bytes(yamlFile)
Expect(err).NotTo(HaveOccurred())

c := discovery.NewDiscoveryClientForConfigOrDie(kc.Config)
groupResources, err := restmapper.GetAPIGroupResources(c)
Expect(err).NotTo(HaveOccurred())

yamlReader := yamlutil.NewYAMLReader(bufio.NewReader(bytes.NewReader(yamlFile)))
for {
yamlDoc, err := yamlReader.Read()

if err != nil {
if errors.Is(err, io.EOF) {
break
}
Expect(err).NotTo(HaveOccurred(), "failed to read yaml file")
}

credentialResource := &unstructured.Unstructured{}
_, _, err = serializer.Decode(yamlDoc, nil, credentialResource)
Expect(err).NotTo(HaveOccurred(), "failed to parse credential resource")

mapper := restmapper.NewDiscoveryRESTMapper(groupResources)
mapping, err := mapper.RESTMapping(credentialResource.GroupVersionKind().GroupKind())
Expect(err).NotTo(HaveOccurred(), "failed to get rest mapping")

dc := kc.GetDynamicClient(schema.GroupVersionResource{
Group: credentialResource.GroupVersionKind().Group,
Version: credentialResource.GroupVersionKind().Version,
Resource: mapping.Resource.Resource,
})

exists, err := dc.Get(ctx, credentialResource.GetName(), metav1.GetOptions{})
if !apierrors.IsNotFound(err) {
Expect(err).NotTo(HaveOccurred(), "failed to get azure credential secret")
}

if exists == nil {
if _, err = dc.Create(ctx, credentialResource, metav1.CreateOptions{}); err != nil {
Expect(err).NotTo(HaveOccurred(), "failed to create azure credential secret")
}
}
}
}

// CreateCredentialSecret uses clusterawsadm to encode existing AWS
// credentials and create a secret in the given namespace if one does not
// already exist.
/*
func CreateCredentialSecret(ctx context.Context, kc *kubeclient.KubeClient) {
GinkgoHelper()
Expand All @@ -65,7 +122,7 @@ func CreateCredentialSecret(ctx context.Context, kc *kubeclient.KubeClient) {
}, metav1.CreateOptions{})
Expect(err).NotTo(HaveOccurred(), "failed to create AWS credentials secret")
}

*/
// PopulateHostedTemplateVars populates the environment variables required for
// the AWS hosted CP template by querying the standalone CP cluster with the
// given kubeclient.
Expand Down

0 comments on commit 8aed88f

Please sign in to comment.