-
Notifications
You must be signed in to change notification settings - Fork 1
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
Refactoring: Support of different deployments kind #30
base: master
Are you sure you want to change the base?
Conversation
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.
Some changes suggested, plus added a couple of questions.
internal/app/upgradeagent/objects.go
Outdated
@@ -4,6 +4,19 @@ import ( | |||
"time" | |||
) | |||
|
|||
// DeploymentClient is a common interface for any deployment kinds. | |||
type DeploymentClient interface { | |||
UpgradeCheck(LocalSolutionInfo) bool |
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.
Would suggest that the names of functions be imperative
, like DoSomething
.
CheckUpgrade
CheckHealth
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. I'll do changes.
@@ -0,0 +1,36 @@ | |||
package upgradeagent | |||
|
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.
Would suggest file names in snake case.
docker_compose_deployment.go
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, I'll rename the files.
@@ -0,0 +1,36 @@ | |||
package upgradeagent | |||
|
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.
Would suggest file names in snake case.
kubernetes_deployment.go
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.
@@ -4,6 +4,19 @@ import ( | |||
"time" | |||
) | |||
|
|||
// DeploymentClient is a common interface for any deployment kinds. | |||
type DeploymentClient interface { |
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.
Whose client is this interface? Which is the server?
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 client of this interface is the Patrao agent. It's not implemented yet. I'm working on it now. I suppose Today evening or Monday morning I'll commit these changes.
} | ||
|
||
// UpstreamClient is a common interface for any upstream service kinds | ||
type UpstreamClient interface { |
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.
Whose client is this interface? Which is the server? Who uses this interface / calls its methods?
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 client of this interface is DeploymentClient. We pass UpstreamClient while creation of DeploymentClient instance and then created instance calls RequestUpgrade() functions. For example, please see func (d *dockerComposeDeployment) UpgradeCheck(localSolutionInfo LocalSolutionInfo) bool implementation. As for the server (ip:port) it will be received from the command line arguments inside the implementation of mockUpstreamClient. Actually in the same way how it's working now.
continue | ||
} | ||
val, exist := containersSpec[serviceName] | ||
if (exist) && (upgradeInfo.Name == solutionName) { |
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.
You can avoid the parentheses.
if val, exist := containersSpec[serviceName]; exist && upgradeInfo.Name == solutionName {
...
}
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.
fixed.
|
||
rc = false | ||
containersSpec := make(map[string]ContainerSpec) | ||
specMap := make(map[string]interface{}) |
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.
Since you're unmarshaling into this map, you don't need to to preallocate. More idiomatic:
var specMap map[string]interface{}
if err := yaml.Unmarshal([]byte(upgradeInfo.Spec), &specMap); err != nil {
...
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.
Since the map variable is a reference type like pointer it has null. So we have to preallocate the map before passing it to yaml.Unmarshal
} | ||
if found { | ||
containersSpec[service.(string)] = ContainerSpec{Name: service.(string), Image: serviceImageName} | ||
} |
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.
Can be simplified:
if val, itemFound := details[DockerComposeImageName]; itemFound {
if serviceImageName, ok := val.(string); ok {
containersSpec[service.(string)] = ContainerSpec{Name: service.(string), Image: serviceImageName}
}
}
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.
fixed.
return false | ||
} | ||
if val, exists := specMap[DockerComposeServicesName]; exists { | ||
servicesMap := val.(map[interface{}]interface{}) |
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.
Will the following work? Might be slightly simpler code. Plus we must check for ok
:
servicesMap, ok := val.(map[string]interface{})
if !ok {
continue
}
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.
fixed.
} | ||
err := os.Mkdir(d.upgradeInfo.Name, os.ModePerm) | ||
if nil != err { | ||
log.Error(err) |
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.
You might want to add meaningful context info to err before logging and returning.
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.
fixed.
if err != nil { | ||
log.Error(err) | ||
return err | ||
} |
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 err = cmd.Run(); err != nil {
...
}
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.
fixed.
return true | ||
} | ||
time.Sleep(1 * time.Second) | ||
} |
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.
You can reduce indentation be removing these {...}.
Resolves #29