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

Refactoring: Support of different deployments kind #30

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions internal/app/upgradeagent/dockercomposedeployment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package upgradeagent

Copy link
Contributor

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

Copy link
Contributor Author

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.

type dockerComposeDeployment struct {
upgradeInfo *UpstreamResponseUpgradeInfo
upstreamClient UpstreamClient
}

// NewDockerComposeDeployment creates a new instance of docker-compose deployment kind.
func NewDockerComposeDeployment(upstreamServiceClient UpstreamClient) DeploymentClient {
return &dockerComposeDeployment{upgradeInfo: NewUpstreamResponseUpgradeInfo(), upstreamClient: upstreamServiceClient}
}

// UpgradeCheck do check if there is a new version of the current solution available
func (d *dockerComposeDeployment) UpgradeCheck(localSolutionInfo LocalSolutionInfo) bool {
if upgradeInfo, isNewVersion := d.upstreamClient.RequestUpgrade(localSolutionInfo); isNewVersion {
d.upgradeInfo = upgradeInfo
return true
}
return false
}

// Upgrade does upgrade the current solution
func (d *dockerComposeDeployment) Upgrade() error {
return nil
}

// Rollback does rollback the current solution to the previous state in case both upgrade or health check is fails
func (d *dockerComposeDeployment) Rollback() {
// TBD
}

// HealthCheck does a health check of the current solution after the upgrade
func (d *dockerComposeDeployment) HealthCheck() bool {
d.upgradeInfo.HealthCheckStatus = Unhealthy
return false
}
36 changes: 36 additions & 0 deletions internal/app/upgradeagent/kubernetesdeployment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package upgradeagent

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok.

type kubernetesDeployment struct {
upgradeInfo *UpstreamResponseUpgradeInfo
upstreamClient UpstreamClient
}

// NewKubernetesDeployment creates a new instance of kubernetes deployment kind.
func NewKubernetesDeployment(upstreamServiceClient UpstreamClient) DeploymentClient {
return &kubernetesDeployment{upgradeInfo: NewUpstreamResponseUpgradeInfo(), upstreamClient: upstreamServiceClient}
}

// UpgradeCheck do check if there is a new version of the current solution available
func (d *kubernetesDeployment) UpgradeCheck(localSolutionInfo LocalSolutionInfo) bool {
if upgradeInfo, isNewVersion := d.upstreamClient.RequestUpgrade(localSolutionInfo); isNewVersion {
d.upgradeInfo = upgradeInfo
return true
}
return false
}

// Upgrade does upgrade the current solution
func (d *kubernetesDeployment) Upgrade() error {
return nil
}

// Rollback does rollback the current solution to the previous state in case both upgrade or health check is fails
func (d *kubernetesDeployment) Rollback() {
// TBD
}

// HealthCheck does a health check of the current solution after the upgrade
func (d *kubernetesDeployment) HealthCheck() bool {
d.upgradeInfo.HealthCheckStatus = Unhealthy
return false
}
14 changes: 14 additions & 0 deletions internal/app/upgradeagent/mockupstreamclient.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package upgradeagent

type mockUpstreamClient struct {
}

// NewMockUpstreamClient returns a new instance of mock upstream service client
func NewMockUpstreamClient() UpstreamClient {
return mockUpstreamClient{}
}

// RequestUpgrade implements the transport layer between Patrao and mocked upstream service
func (mock mockUpstreamClient) RequestUpgrade(solutionInfo LocalSolutionInfo) (*UpstreamResponseUpgradeInfo, bool) {
return nil, false
}
13 changes: 13 additions & 0 deletions internal/app/upgradeagent/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ import (
"time"
)

// DeploymentClient is a common interface for any deployment kinds.
type DeploymentClient interface {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

UpgradeCheck(LocalSolutionInfo) bool
Copy link
Contributor

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

Copy link
Contributor Author

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.

Upgrade() error
HealthCheck() bool
Rollback()
}

// UpstreamClient is a common interface for any upstream service kinds
type UpstreamClient interface {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

RequestUpgrade(LocalSolutionInfo) (*UpstreamResponseUpgradeInfo, bool)
}

// KindType Kind type for all structures
type KindType string

Expand Down