-
Notifications
You must be signed in to change notification settings - Fork 174
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
A huge migration to a newer swagger. #3481
Conversation
fixes #929 ? |
@@ -615,7 +616,7 @@ func TestPortInformation(t *testing.T) { | |||
mockContainerInfo := &plmodels.ContainerInfo{} | |||
mockContainerConfig := &plmodels.ContainerConfig{} | |||
containerID := "foo" | |||
mockContainerConfig.ContainerID = &containerID | |||
mockContainerConfig.ContainerID = containerID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a lot of these changes where we are taking away the pointer. Can we not do these in a separate PR; preferably in an iterative manner? These kinds of changes always have the danger of introducing subtle bugs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the least problematic change you can think of - at least for these values I was able to check the code surrounding it. The most scariest part is when I set "x-nullable":false - this is where zero values are no longer accepted. I tried to be careful with them, but things that are changed are not as scary as those that are unchanged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, yes, this one in particular is not problematic. But that doesn't mean the multitude of others is not; its just not easy to go through everyone and understand the ramifications of a particular change. Is the "x-nullable" really necessary right now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hmahmood without it the change would be an order of a magnitude larger.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hmahmood the good part of this change is that it will expose problematic parts of our API and data checks earlier. What really worries me is that we do not really care about data validation relaying purely on a sane usage. At the moment it is fine, but AFAIK PortLayer API will be exposed in the future, so absence of data validation will bite us.
My take on this is let's get it tested as much as possible. Run against the CI, the Nightlies, Stress and Longevity. We should aim to get it in sooner so that we can continue to iterate on it. |
if container == nil { | ||
log.Errorf("Could not find container with ID %s", *t.ContainerConfig.ContainerID) | ||
cid := t.ContainerConfig.ContainerID | ||
c := cache.ContainerCache().GetContainer(cid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. I really hate go programmer's habit of overloading one line with a bazillion operations. They need to remember the compiler doesn't care, and readability is more important.
|
||
"github.com/vmware/vic/lib/apiservers/engine/backends/cache" | ||
"github.com/vmware/vic/lib/apiservers/engine/backends/container" | ||
"github.com/vmware/vic/lib/apiservers/portlayer/client" | ||
apiclient "github.com/vmware/vic/lib/apiservers/portlayer/client" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apiclient
isn't really necessary to migrate from 1 swagger version to another. We can debate the naming of this later. Lets keep this change restricted only only the required changes to include the new swagger version. The unnecessary churn makes reviewing harder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used tools to deal with imports, all automatic changes are not easy to manage manually.
@@ -123,52 +124,52 @@ func hydrateCaches() error { | |||
|
|||
wg := sync.WaitGroup{} | |||
wg.Add(waiters) | |||
errors := make(chan error, waiters) | |||
errChan := make(chan error, waiters) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above. This isn't strictly necessary to migrate to the new swagger version. Please remove it from your change and we can review these cosmetic changes in a different PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the cosmetic change and the only one that you can say "big".
@@ -985,22 +984,25 @@ func (c *Container) ContainerInspect(name string, size bool, version version.Ver | |||
} | |||
var started time.Time | |||
var stopped time.Time | |||
if results.Payload.ProcessConfig.StartTime != nil && *results.Payload.ProcessConfig.StartTime > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this purely formatting? Unnecessary churn to migrate to the new swagger. Encapsulate these cosmetic changes in their own PR and we can review them later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a cosmetic change. it a result of a variable becoming a value not a pointer during migration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fdawg4l There are a few cosmetic changes, but I would gloss over them and focus on the pointer issue. Vast majority of the changes I've seen so far are due to Swagger and not cosmetic.
if vchInfo.Memory != nil { | ||
info.MemTotal = *vchInfo.Memory << 20 //Multiply by 1024*1024 to get Mebibytes | ||
if vchInfo.Memory > 0 { | ||
info.MemTotal = vchInfo.Memory * 1024 * 1024 // Get Mebibytes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
come one - 2^20 FTW :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to keep it as is also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
come one - compiler will do the same thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, if go compiler is smart to do this. Still hurts the eyes of former C/C++ programmers. :)
@@ -1,225 +0,0 @@ | |||
package {{ .APIPackage }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we needed this for 030764a . How do we handle it with new swagger?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to verify it is still the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1244 is the original issue for your reference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@caglar10ur Thanks for a good catch. I am going to backport this change directly into swagger, since it is actually makes sense. I was about to implement same thing on my previous projects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@caglar10ur I integrated needed changes into swagger as well as updated portlayer accordingly.
go-swagger/go-swagger#784
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
} | ||
|
||
// Ping sends an OK response to let the client know the server is up | ||
func (handler *MiscHandlersImpl) Ping() middleware.Responder { | ||
func (h *MiscHandlersImpl) Ping(param misc.PingParams) middleware.Responder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parameter-less operations in the swagger spec now causes parameters to be generated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, they contain some useful objects like context, request, etc.
sc := &models.ScopeConfig{ | ||
ID: &id, | ||
ID: scope.ID().String(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems a little inconsistent. Some places, you're introducing new vars for readability, but then you remove them in other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case it makes sense, since it is a short string, I can see all at once.
"type": "integer", | ||
"format": "int64" | ||
"x-nullable": false, | ||
"type": "integer" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a type integer instead of int64 now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format != type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version of Swagger we used caused an int64 to get generated if we tag the parameter with format. Latest version of Swagger no longer does this?
"type": "string" | ||
}, | ||
"createTime": { | ||
"type": "integer", | ||
"format": "int64" | ||
"type": "integer" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is Swagger defaulting to in64 now? I believe unix time is int64.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it always was :-|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it wasn't it would not compile.
@@ -2721,8 +2763,7 @@ | |||
"$ref": "#/definitions/ReservationConfig" | |||
}, | |||
"storageSize": { | |||
"type": "integer", | |||
"format": "int64" | |||
"type": "integer" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above. Why integer instead of int64?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After our slack conversation, I see that integer now defaults to int64 in the latest Swagger generator.
Nothing seemed out of the ordinary. We'll just have to be aware of x-nullable and integer generation changes. Is this the extent of all the changes necessary? lgtm |
LGTM |
LGTM |
What can I say? It is a HUGE change. Full CI passed, which is exciting and scary at the same time. Not sure there is a good way to review it all carefully, pick a part you are familiar with and see what happens.
Fixes: #929