-
Notifications
You must be signed in to change notification settings - Fork 243
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
Fixes odo update from git to binary/local and vice versa #518
Conversation
pkg/component/component.go
Outdated
var err error | ||
projectName := client.GetCurrentProjectName() | ||
from, _, ctype, err := GetComponentSource(client, componentName, applicationName, projectName) |
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 is a function to return Component type - GetComponentType
. You shouldn't modify GetComponentSource
just to get this information.
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.
@kadel Ok sorry forgot that there was a function for getting the component 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.
URLs are deleted after the component is updated
@kadel Ok What are the other components that need to be preserved before the deletion? |
everything ;-) |
Also after running an update from 'local' to 'binary' DeploymentConfig still has annotations as 'local' component. |
@kadel I mean storage, urls and? I might be forgetting more |
I think that is all. As rule you shouldn't touch anything expect DeploymentConfigs and BuildConfigs |
72626fa
to
69e1d26
Compare
@kadel Done. I have updated the approach and now it does not delete the component before the update instead it updates the buildConfig, deploymentConfigs and triggers the build. Please have a look. |
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 looks like it works, but to make sure we need to have a good test suite probably (e2e) that will test all possible update combinations.
This also needs unit tests.
pkg/occlient/occlient.go
Outdated
// AddBootstrapInitContainer adds the bootstrap init container to the deployment config | ||
// dc is the deployment config to be updated | ||
// dcName is the name of the deployment config | ||
func (c *Client) AddBootstrapInitContainer(dc *appsv1.DeploymentConfig, dcName 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.
Does this function need Client
receiver?
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.
No, I guess, I will remove it. Also should I make it private?
pkg/occlient/occlient.go
Outdated
// dc is the deployment config to be updated | ||
// dcName is the name of the deployment config | ||
func (c *Client) AddBootstrapInitContainer(dc *appsv1.DeploymentConfig, dcName string) { | ||
appRootVolumeName := fmt.Sprintf("%s-s2idata", dcName) |
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.
appRootVolumeName is constructed in the multiple places. Could we generate this name in one place?
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 will create a private function to fetch this
pkg/occlient/occlient.go
Outdated
// AddBootstrapVolume adds the bootstrap volume to the deployment config | ||
// dc is the deployment config to be updated | ||
// dcName is the name of the deployment config | ||
func (c *Client) AddBootstrapVolume(dc *appsv1.DeploymentConfig, dcName 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.
Does this function need Client
receiver?
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.
No, I guess, I will remove it. Also should I make it private?
pkg/occlient/occlient.go
Outdated
// AddBootstrapVolumeMount mounts the bootstrap volume to the deployment config | ||
// dc is the deployment config to be updated | ||
// dcName is the name of the deployment config | ||
func (c *Client) AddBootstrapVolumeMount(dc *appsv1.DeploymentConfig, dcName 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.
Does this function need Client
receiver?
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.
No, I guess, I will remove it. Also should I make it private?
pkg/occlient/occlient.go
Outdated
// UpdateBuildConfig updates the BuildConfig file | ||
// buildConfigName is the name of the BuildConfig file to be updated | ||
// projectName is the name of the project | ||
// gitUrl equals to the git URL of the source and is equals to "" if the source is of type dir or binary | ||
// annotations contains the annotations for the BuildConfig file | ||
func (c *Client) UpdateBuildConfig(buildConfigName string, projectName string, gitUrl string, annotations map[string]string) error { | ||
const bootstrapperURI = "https://github.com/kadel/bootstrap-supervisored-s2i" |
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 duplicate, it is already defined in Boostrap function
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.
Should I make it a global variable?
pkg/occlient/occlient.go
Outdated
@@ -876,6 +910,81 @@ func (c *Client) UpdateBuildConfig(buildConfigName string, projectName string, g | |||
return nil | |||
} | |||
|
|||
// AddSupervisorToDC adds the supervisor to the deployment config |
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'm not sure that this is the correct name for this function. It doesn't add a supervisor to the deployment config. The supervisor is added to the image via BuildConfig, this just adds initContainer and volume that is needed for it work properly
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.
@kadel Can you suggest any name? I am confused
pkg/occlient/occlient.go
Outdated
// builderImage is the name of the builderImage type | ||
// projectName is the name of the project | ||
// annotations are the updated annotations for the new deployment config | ||
func (c *Client) RemoveSupervisorFromDC(dcName string, builderImage string, projectName string, annotations map[string]string) error { |
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.
similar concern as with AddSupervisorToDC
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.
@kadel Can you suggest any name? I am confused here too
45fc5a8
to
880796d
Compare
d30eb22
to
a26749c
Compare
tests/e2e/e2e_test.go
Outdated
"{{.name}}{{end}}{{end}}'") | ||
Expect(getDc).To(ContainSubstring("wildfly" + appRootVolumeName)) | ||
|
||
// checking for source-type in dc |
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 could create function rather than copy/pasting those 4 check this to every test ;-)
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 good idea 👍
5581d81
to
7e04722
Compare
a644bd9
to
52d62b8
Compare
@@ -79,6 +79,10 @@ test-e2e: | |||
test-demo: | |||
go test -v github.com/redhat-developer/odo/tests/e2e --ginkgo.focus="katacodaDemo" -ginkgo.v | |||
|
|||
.PHONY: test-update-e2e | |||
test-update-e2e: |
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 suspect that those tests are never run on travis :-(
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.
Yep, need to make a travis.yml entry for this. Something like this: https://github.com/redhat-developer/odo/blob/master/.travis.yml#L46
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 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.
@mik-dass Fantastic!
New changes LGTM! |
pkg/component/component.go
Outdated
@@ -330,7 +330,7 @@ func GetComponentSource(client *occlient.Client, componentName string, applicati | |||
// Component name is the name component to be updated | |||
// to indicates what type of source type the component source is changing to e.g from git to local or local to binary |
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.
arguments for this function were changes, comment needs to reflect that
pkg/occlient/occlient.go
Outdated
@@ -55,6 +55,9 @@ const ( | |||
|
|||
// The length of the string to be generated for names of resources | |||
nameLength = 5 | |||
// git repository that will be used for bootstraping | |||
bootstrapperURI = "https://github.com/kadel/bootstrap-supervisored-s2i" | |||
bootstrapperRef = "v0.0.1" |
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 are using v0.0.2
now, why is this downgraded?
pkg/component/component.go
Outdated
annotations[componentSourceTypeAnnotation] = to | ||
err = client.UpdateBuildConfig(namespacedOpenShiftObject, projectName, "", annotations) | ||
} | ||
log.Debugf("Updating component %s, to %s (%s).", componentName, newSource, newSourceType) |
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.
Shouldn't it be:
"Updating component from %s to %s"
pkg/occlient/occlient.go
Outdated
|
||
// SetupForSupervisor adds the supervisor to the deployment config | ||
// dcName is the name of the deployment config to be updated | ||
// builderImage is the name of the builderImage 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.
there is no "builderImage" in this function
pkg/occlient/occlient.go
Outdated
|
||
// CleanupAfterSupervisor removes the supervisor from the deployment config | ||
// dcName is the name of the deployment config to be updated | ||
// builderImage is the name of the builderImage 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.
there is no "builderImage" in this function
pkg/occlient/occlient.go
Outdated
// builderImage is the name of the builderImage type | ||
// projectName is the name of the project | ||
// annotations are the updated annotations for the new deployment config | ||
func (c *Client) SetupForSupervisor(dcName string, projectName string, annotations map[string]string, labels map[string]string) error { |
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.
what is labels
argument?
It would be explained why it is used only in CreatePVC
tests/e2e/e2e_test.go
Outdated
@@ -103,6 +103,24 @@ func waitForCmdOut(cmd string, expOut string) bool { | |||
} | |||
} | |||
|
|||
func SourceTest(appTestName string, source string, sourceType 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.
needs comment explaining what this function is for
tests/e2e/e2e_test.go
Outdated
@@ -422,3 +449,314 @@ var _ = Describe("odoe2e", func() { | |||
}) | |||
}) | |||
}) | |||
|
|||
var _ = Describe("updateE2e", func() { | |||
appTestName := "testing" |
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.
shouldn't be this and following variables constants?
7cb69d8
to
eccf6e0
Compare
@kadel I have made the changes, please have a look again |
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.
last comments ;-)
tests/e2e/e2e_test.go
Outdated
|
||
var _ = Describe("updateE2e", func() { | ||
|
||
bootStrapSupervisorURI := "https://github.com/kadel/bootstrap-supervisored-s2i" |
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.
Shouldn't this variables be constant?
tests/e2e/e2e_test.go
Outdated
}) | ||
|
||
It("should update component from binary to local", func() { | ||
runCmd("git clone https://github.com/marekjelen/katacoda-odo-backend " + |
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 are you not using wildflyUri1
?`
tests/e2e/e2e_test.go
Outdated
}) | ||
|
||
It("should update component from local to git", func() { | ||
runCmd("odo update wildfly --git https://github.com/marekjelen/katacoda-odo-backend") |
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 are you not using wildflyUri1?
tests/e2e/e2e_test.go
Outdated
}) | ||
|
||
It("should update component from binary to git", func() { | ||
runCmd("odo update wildfly --git https://github.com/marekjelen/katacoda-odo-backend") |
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 are you not using wildflyUri1?
tests/e2e/e2e_test.go
Outdated
}) | ||
|
||
It("should update component from local to local", func() { | ||
runCmd("git clone https://github.com/mik-dass/katacoda-odo-backend " + |
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 are you not using wildflyUri2
?
tests/e2e/e2e_test.go
Outdated
}) | ||
|
||
It("should update component from git to git", func() { | ||
runCmd("odo update wildfly --git https://github.com/mik-dass/katacoda-odo-backend") |
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 are you not using wildflyUri2
?
@kadel Done |
To achieve this, two functions have been added SetupForSupervisor and CleanupAfterSupervisor in occlient.go. Also some other functions are added in occlient to add and remove initContainers, volumeMounts and volumes to the deploymentConfig. Also updateDcAnnotations in occlient is added to update the annotations in the deploymentConfig. Signed-off-by: mdas <mrinald7@gmail.com>
@mik-dass Please update the commit description as well as the PR description before this is merged 👍 |
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.
@kadel I have edited @mik-dass 's PR description with what he put in the commit description!
Mergin' time |
t.Errorf("created PVC spec not matching with expected values, expected: %s, got %s", createdPVC.Spec, tt.createdPVC.Spec) | ||
} | ||
} else if err == nil && tt.wantErr { | ||
t.Errorf("test failed, expected: %s, got %s", "error", "no error") |
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 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'm assuming you're refereing for the part that it should be err
and tt.wantErr
for the "error" and "no error" parts?
} else if err == nil && tt.wantErr { | ||
t.Errorf("test failed, expected: %s, got %s", "error", "no error") | ||
} else if err != nil && !tt.wantErr { | ||
t.Errorf("test failed, expected: %s, got %s", "no error", "error") |
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.
😞
To achieve this, two functions have been added SetupForSupervisor and CleanupAfterSupervisor in occlient.go. Also some other functions are added in occlient to add and remove initContainers, volumeMounts and volumes to the deploymentConfig. Also updateDcAnnotations in occlient is added to update the annotations in the deploymentConfig.
Issue: #439
Signed-off-by: mdas mrinald7@gmail.com