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

Implement Azure e2e template tests #300

Closed
wants to merge 1 commit into from

Conversation

kylewuolle
Copy link
Contributor

@kylewuolle kylewuolle commented Sep 12, 2024

Implement Azure template e2e tests.

@squizzi
Copy link

squizzi commented Sep 12, 2024

You'll need to reopen this with a repository branch and modify the test to run as pull_request or just rebase off my PR, #280 since there's a bunch of test related fixes in there. Then you'll be able to see if the tests pass and iterate on them before we merge it in as pull_request_target. This is the best way I can think of to do this until we have more time to figure out the secrets stuff in actions.

}

if exists == nil {
if _, err = dc.Create(ctx, credentialResource, metav1.CreateOptions{}); err != nil {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't even need to call .Get prior to .Create you can just call .Create and then check for apierrors.IsAlreadyExists(err) and return nil in that case.

yamlDoc, err := yamlReader.Read()

if err != nil {
if err == io.EOF {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if err == io.EOF {
if errors.Is(err, io.EOF) {

return fmt.Errorf("failed to read azure credential file: %w", err)
}

yamlFile, err = envsubst.Bytes(yamlFile)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're going to perform substitutions on the file it should probably be a .tpl file. Perhaps create an resources/azure-credentials.yaml.tpl and embed it above and then call envsubst on it.

@@ -123,6 +131,75 @@ func new(configBytes []byte, namespace string) (*KubeClient, error) {
}, nil
}

func (kc *KubeClient) CreateAzureCredentialsKubeSecret(ctx context.Context) error {
serializer := yaml.NewDecodingSerializer(unstructured.UnstructuredJSONScheme)
yamlFile, err := os.ReadFile("./config/dev/azure-credentials.yaml")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of calling os.ReadFile on a path that might change use go:embed to embed the file at runtime, see: https://gobyexample.com/embed-directive you can embed directly into []byte and then manipulate it as needed below.

GinkgoHelper()

generatedName := uuid.New().String()[:8] + "-e2e-test"
generatedName := "e2etest-" + uuid.New().String()[:8]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this name doesn't align with the one ran in CI, if you want to change that name to make sure you modify MANAGED_CLUSTER_NAME in the actions workflow when you rebase.

@@ -41,7 +43,7 @@ func VerifyProviderDeleted(ctx context.Context, kc *kubeclient.KubeClient, clust
func validateClusterDeleted(ctx context.Context, kc *kubeclient.KubeClient, clusterName string) error {
// Validate that the Cluster resource has been deleted
cluster, err := kc.GetCluster(ctx, clusterName)
if err != nil {
if err != nil && !apierrors.IsNotFound(err) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Collaborator

@a13x5 a13x5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hosted test looks incorrect, should be rechecked and reworked.
Since hosted cluster should be create on cluster which is deployed on Azure. Also artifacts should be passed there somehow. I don't see any of that.
Probably you should wait for #280 to be merged and then build hosted CP tests on top of that.


for _, template := range []managedcluster.Template{
managedcluster.TemplateAzureStandaloneCP,
managedcluster.TemplateAzureHostedCP,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're creating hosted cluster template in the local kind cluster. It should fail. And if it's not - the test should be reworked

@@ -123,6 +131,75 @@ func new(configBytes []byte, namespace string) (*KubeClient, error) {
}, nil
}

func (kc *KubeClient) CreateAzureCredentialsKubeSecret(ctx context.Context) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks more complex than it should be. @squizzi already proposed several fixes and I tend to agree with him

@kylewuolle kylewuolle closed this Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants