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

Fixed issue with compat/client with applying empty structures to api server #454

Merged

Conversation

Danil-Grigorev
Copy link
Contributor

@Danil-Grigorev Danil-Grigorev commented Mar 17, 2020

Re-implementing functionality of #443

  • Added downconvert for cronjobs

@Danil-Grigorev Danil-Grigorev changed the title [WIP] Added generated conversion function for appsv1 Added generated conversion function for appsv1 Mar 18, 2020
@Danil-Grigorev Danil-Grigorev marked this pull request as ready for review March 18, 2020 14:20
@Danil-Grigorev Danil-Grigorev changed the title Added generated conversion function for appsv1 Fixed issue with compat/client with applying empty structures to api server Mar 19, 2020
@Danil-Grigorev Danil-Grigorev added kind/bug Categorizes issue or PR as related to a bug. and removed PoC labels Mar 19, 2020
@Danil-Grigorev
Copy link
Contributor Author

Danil-Grigorev commented Mar 19, 2020

@jortel This should be a smaller scoped PR, only addressing the issue with resource name being empty. Please review.

{"level":"info","ts":1584511208.2217383,"logger":"migration|j8589","msg":"[RUN]","migration":"mssql-app-mig-1584510245","stage":false,"phase":"QuiesceApplications"}
{"level":"error","ts":1584511209.0168467,"logger":"migration|j8589","msg":"","migration":"mssql-app-mig-1584510245","error":"resource name may not be empty","stacktrace":"github.com/konveyor/mig-controller/vendor/github.com/go-logr/zapr.(*zapLogger).Error\n\t/go/src/github.com/konveyor/mig-controller/vendor/github.com/go-logr/zapr/zapr.go:128\ngithub.com/konveyor/mig-controller/pkg/logging.Logger.Error\n\t/go/src/github.com/konveyor/mig-controller/pkg/logging/logger.go:75\ngithub.com/konveyor/mig-controller/pkg/logging.Logger.Trace\n\t/go/src/github.com/konveyor/mig-controller/pkg/logging/logger.go:81\ngithub.com/konveyor/mig-controller/pkg/controller/migmigration.(*Task).scaleDownDeployments\n\t/go/src/github.com/konveyor/mig-controller/pkg/controller/migmigration/quiesce.go:110\ngithub.com/konveyor/mig-controller/pkg/controller/migmigration.(*Task).quiesceApplications\n\t/go/src/github.com/konveyor/mig-controller/pkg/controller/migmigration/quiesce.go:31\ngithub.com/konveyor/mig-controller/pkg/controller/migmigration.(*Task).Run\n\t/go/src/github.com/konveyor/mig-controller/pkg/controller/migmigration/task.go:283\ngithub.com/konveyor/mig-controller/pkg/controller/migmigration.(*ReconcileMigMigration).migrate\n\t/go/src/github.com/konveyor/mig-controller/pkg/controller/migmigration/migrate.go:78\ngithub.com/konveyor/mig-controller/pkg/controller/migmigration.(*ReconcileMigMigration).Reconcile\n\t/go/src/github.com/konveyor/mig-controller/pkg/controller/migmigration/migmigration_controller.go:195\ngithub.com/konveyor/mig-controller/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\t/go/src/github.com/konveyor/mig-controller/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:215\ngithub.com/konveyor/mig-controller/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func1\n\t/go/src/github.com/konveyor/mig-controller/vendor/sigs.k8s.io/controller-runtime/pkg/internal/controller/controller.go:158\ngithub.com/konveyor/mig-controller/vendor/k8s.io/apimachinery/pkg/util/wait.JitterUntil.func1\n\t/go/src/github.com/konveyor/mig-controller/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:133\ngithub.com/konveyor/mig-controller/vendor/k8s.io/apimachinery/pkg/util/wait.JitterUntil\n\t/go/src/github.com/konveyor/mig-controller/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:134\ngithub.com/konveyor/mig-controller/vendor/k8s.io/apimachinery/pkg/util/wait.Until\n\t/go/src/github.com/konveyor/mig-controller/vendor/k8s.io/apimachinery/pkg/util/wait/wait.go:88"}

@@ -109,11 +122,9 @@ func (c Client) Get(ctx context.Context, key k8sclient.ObjectKey, in runtime.Obj
if err != nil {
return err
}
if in != obj {
Copy link
Contributor

Choose a reason for hiding this comment

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

The purpose for this check is so that we don't up-convert the result unless it was down-converted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it is already being done in the scheme.Convert

Copy link
Contributor

@jortel jortel Mar 19, 2020

Choose a reason for hiding this comment

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

Drilling down in the code, it seems it's still doing some work we could/should avoid. Thoughts?
The check provides some symmetry in that we conditionally convert as needed both up and down.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed

@@ -151,6 +164,10 @@ func (c Client) Create(ctx context.Context, in runtime.Object) error {
// The resource will be converted to a compatible version as needed.
func (c Client) Delete(ctx context.Context, in runtime.Object, opt ...k8sclient.DeleteOptionFunc) error {
obj := c.downConvert(in)
err := scheme.Scheme.Convert(in, obj, ctx)
Copy link
Contributor

@jortel jortel Mar 19, 2020

Choose a reason for hiding this comment

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

Seems like doing the down-conversion in the downConvert() method would make more sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

return c.Client.Update(ctx, obj)
}

func (c Client) Status() k8sclient.StatusWriter {
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought this was needed to implement the Client interface. No?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is inheriting that from the client inside the structure.

continue
}
unstructured.SetNestedField(r.Object, true, fields...)
r.Spec.Suspend = pointer.BoolPtr(true)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 Using pointer.BoolPtr() is so much cleaner than using a bool variable.

if c.Minor < 16 {
switch obj.(type) {
Copy link
Contributor

@jortel jortel Mar 20, 2020

Choose a reason for hiding this comment

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

Cast to Type and switch statement is a nice improvement.

@jortel
Copy link
Contributor

jortel commented Mar 20, 2020

@Danil-Grigorev These changes look really good but no longer include a few changes I recall seeing in earlier versions of the PR. Mainly files related to generating the conversions. Earlier you added the conversion-gen to our Makefile but no longer see that diff. Also, IIRC you added a subpackage to our compat package with generated conversions that I no longer see in the diff.
Are the additions to /vendor still needed?

@Danil-Grigorev
Copy link
Contributor Author

Danil-Grigorev commented Mar 23, 2020

@Danil-Grigorev These changes look really good but no longer include a few changes I recall seeing in earlier versions of the PR. Mainly files related to generating the conversions. Earlier you added the conversion-gen to our Makefile but no longer see that diff. Also, IIRC you added a subpackage to our compat package with generated conversions that I no longer see in the diff.

Look into PR #460, those two PRs are addressing different issues.

Are the additions to /vendor still needed?

Yes, they are needed for BoolPtr methods.

@jortel Tested this in a full setup, everything works.

Copy link
Contributor

@jortel jortel left a comment

Choose a reason for hiding this comment

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

LGTM

@Danil-Grigorev Danil-Grigorev merged commit 424d13a into migtools:master Mar 23, 2020
@Danil-Grigorev Danil-Grigorev deleted the downscale-conversion-fix branch March 23, 2020 16:43
dymurray pushed a commit that referenced this pull request Mar 23, 2020
…server (#454)

* Fixed issue with compat/client with applying empty structures to api server

- Added downconvert to cronjobs

* Added up and down conversion functions

(cherry picked from commit 424d13a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. release-1.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants