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

Add yaml outputs of resources to streaming logs and add import&update steps to uptest #136

Merged
merged 7 commits into from
Oct 5, 2023

Conversation

sergenyalcin
Copy link
Member

@sergenyalcin sergenyalcin commented Sep 28, 2023

Description of your changes

  • This PR adds yaml outputs of resources to streaming log while waiting the Ready condition. Kuttl has a script field for supporting multiple commands.
  • This PR adds new two test steps to uptest: import and update

I have:

  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

Tested locally.

Signed-off-by: Sergen Yalçın <[email protected]>
@sergenyalcin sergenyalcin changed the title Add yaml outputs of resources to streaming log while waiting the Ready condition Add yaml outputs of resources to streaming logs and add import&update steps to uptest Oct 3, 2023
@sergenyalcin sergenyalcin self-assigned this Oct 3, 2023
Copy link
Contributor

@ulucinar ulucinar left a comment

Choose a reason for hiding this comment

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

Thanks @sergenyalcin, lgtm. If we have a bug in the resource updates, let's not hide that as we have discussed.

@@ -17,6 +17,10 @@ on:
default: 'provider'
required: false
type: string
update-test-parameter:
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: We may consider adding a description to the new parameter.

Let's also document that the update parameter should be a serialized JSON object and if the JSON object has nested children, then there must be only one leaf.

@@ -12,7 +13,7 @@ commands:
{{- end }}
{{- range $condition := $resource.Conditions }}
{{- if $resource.Namespace }}
- command: ${KUBECTL} wait {{ $resource.KindGroup }}/{{ $resource.Name }} --for=condition={{ $condition }} --timeout 10s --namespace {{ $resource.Namespace }}
- script: ${KUBECTL} get --namespace {{ $resource.Namespace }} {{ $resource.KindGroup }}/{{ $resource.Name }} -o yaml && ${KUBECTL} wait {{ $resource.KindGroup }}/{{ $resource.Name }} --for=condition={{ $condition }} --timeout 10s --namespace {{ $resource.Namespace }}
Copy link
Contributor

Choose a reason for hiding this comment

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

We may just dump all the claims above with the MRs:

Suggested change
- script: ${KUBECTL} get --namespace {{ $resource.Namespace }} {{ $resource.KindGroup }}/{{ $resource.Name }} -o yaml && ${KUBECTL} wait {{ $resource.KindGroup }}/{{ $resource.Name }} --for=condition={{ $condition }} --timeout 10s --namespace {{ $resource.Namespace }}
- script: ${KUBECTL} wait {{ $resource.KindGroup }}/{{ $resource.Name }} --for=condition={{ $condition }} --timeout 10s --namespace {{ $resource.Namespace }}

@@ -3,6 +3,7 @@ kind: TestAssert
timeout: {{ .TestCase.Timeout }}
commands:
- command: ${KUBECTL} annotate managed --all upjet.upbound.io/test=true --overwrite
- command: ${KUBECTL} get managed -o yaml
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- command: ${KUBECTL} get managed -o yaml
- script: ${KUBECTL} get managed -o yaml || ${KUBECTL} get claim --all-namespaces -o yaml

@@ -3,6 +3,7 @@ kind: TestAssert
timeout: {{ .TestCase.Timeout }}
commands:
- command: ${KUBECTL} annotate managed --all upjet.upbound.io/test=true --overwrite
- command: ${KUBECTL} get managed -o yaml
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: We had better include a header in the debug log messages like Dumping all MRs: , Dumping all claims: .

{{- if eq $resource.KindGroup "secret." -}}
{{continue}}
{{- end -}}
{{- if not $resource.Namespace }}
Copy link
Contributor

Choose a reason for hiding this comment

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

In the next iteration, we can consider adding claim update tests.

for key, value := range data {
newPath := currentPath + "." + key
switch v := value.(type) {
case map[string]interface{}:
Copy link
Contributor

Choose a reason for hiding this comment

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

We may capture in the description of the update parameter that only maps & nested objects are supported.

@@ -81,6 +82,15 @@ func (t *tester) prepareConfig() (*config.TestCase, []config.Resource, error) {
Conditions: t.options.DefaultConditions,
}

if updateParameter := os.Getenv("UPTEST_UPDATE_PARAMETER"); updateParameter != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if updateParameter := os.Getenv("UPTEST_UPDATE_PARAMETER"); updateParameter != "" {
updateParameter := ... // get value from annotation
if updateParameter == "" {
updateParameter = os.Getenv("UPTEST_UPDATE_PARAMETER")
}
if updateParameter != "" {
...

Comment on lines +9 to +10
- command: ${KUBECTL} --subresource=status patch {{ $resource.KindGroup }}/{{ $resource.Name }} --type=merge -p '{"status":{"conditions":[]}}'
- script: ${KUBECTL} annotate {{ $resource.KindGroup }}/{{ $resource.Name }} uptest-old-id=$(${KUBECTL} get {{ $resource.KindGroup }}/{{ $resource.Name }} -o=jsonpath='{.status.atProvider.id}') --overwrite
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: We have better scale the provider deployment down before updating the status and putting the annotation here.

{{continue}}
{{- end -}}
{{- if $resource.Namespace }}
- script: ${KUBECTL} get --namespace {{ $resource.Namespace }} {{ $resource.KindGroup }}/{{ $resource.Name }} -o yaml --ignore-not-found && ${KUBECTL} wait {{ $resource.KindGroup }}/{{ $resource.Name }} --for=delete --timeout 10s --namespace {{ $resource.Namespace }}
Copy link
Contributor

Choose a reason for hiding this comment

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

We may consider moving the kubectl get outside the loop.


// assertUpdatedFileTemplate is the template for update assert file.
//
//go:embed 01-assert.yaml.tmpl
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
//go:embed 01-assert.yaml.tmpl
//go:embed 01-assert-update.yaml.tmpl

{{continue}}
{{- end -}}
{{- if not $resource.Namespace }}
- command: ${KUBECTL} patch {{ $resource.KindGroup }}/{{ $resource.Name }} --type=merge -p '{"spec":{"forProvider":{{ $resource.UpdateParameter }}}}'
Copy link
Contributor

Choose a reason for hiding this comment

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

We had better only patch the target manifest in the update tests.

Signed-off-by: Sergen Yalçın <[email protected]>
Signed-off-by: Sergen Yalçın <[email protected]>
@sergenyalcin sergenyalcin merged commit 61e5bb8 into upbound:main Oct 5, 2023
5 checks passed
@sergenyalcin sergenyalcin deleted the improvements branch October 5, 2023 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants