-
Notifications
You must be signed in to change notification settings - Fork 244
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
List components from other sources #4742
List components from other sources #4742
Conversation
d720aa1
to
8b668b5
Compare
if err != nil { | ||
return ComponentList{}, errors.Wrap(err, "Unable to get component") | ||
} |
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 have a question here. Why do we return if err!=nil
even though there are some other checks pending in the function, for e.g. this check - https://github.com/openshift/odo/pull/4742/files#diff-a84453ec52dba47b60234fd3aba56849e52e2bae2577c082dcf1a79ef6b25855R946 ?
if client != nil {
Why do we avoid that and return? Shouldn't we check for if err == nil { continue }
and execute rest of the code? I have seen this type of logic in almost all places. For some it makes sense, but for others I think we should continue executing the program and if it does not make sense to do so, then perhaps we should add a comment about why we are returning without executing the rest of the code.
Other examples are -
- pkg/odo/cli/component/list.go:264 - https://github.com/openshift/odo/pull/4742/files#diff-a5ee7fb0c76cd592580dce46cda117d8a483452979b0da40d644906f88cba343R264
- pkg/odo/cli/component/list.go:274 - https://github.com/openshift/odo/pull/4742/files#diff-a5ee7fb0c76cd592580dce46cda117d8a483452979b0da40d644906f88cba343R274
- ..and many more
tests/integration/component.go
Outdated
Context("when components are not created/managed by odo", func() { | ||
var appName, compName string | ||
JustBeforeEach(func() { | ||
//CreateNonOdoComponent |
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 someone help me with this one? I plan on creating a deployment and deployment-config manually via API, but I need to prepare a lot of data before doing that. Do we already have helper functions that might help here?
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 just create deployment.yaml
with the most simple deployment that you can come up with. Add the same labels to it as WebConsole does and just call kubectl apply -f deplyomet.yaml
pkg/component/component.go
Outdated
@@ -1651,13 +1642,16 @@ func GetMachineReadableFormatForList(s2iComps []Component) ComponentList { | |||
} | |||
|
|||
// GetMachineReadableFormatForCombinedCompList returns list of devfile and s2i components in machine readable format |
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.
maybe update this comment?
// To pass operands such as !=, append a ! prefix to the value. | ||
// For E.g. map[string]string{"app.kubernetes.io/managed-by": "!odo"} | ||
// Using != operators also means that resource will be filtered even if it doesn't have the key. | ||
// So a resource not labelled with key "app.kubernetes.io/managed-by" will also be returned. | ||
func ConvertLabelsToSelector(labels map[string]string) 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.
why not extend the labels here to be a list of structs here like
struct {
Key string
Value string
Operand Operand
}
type Operand string
var Equal Operand = "="
var NotEqual Operand = "!="
might be more future proof?
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 you elaborate?
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.
instead of this label map
labels map[string]string
struct {
Key string
Value string
Operand Operand
}
type Operand string
var Equal Operand = "="
var NotEqual Operand = "!="
So the function would look like this ConvertLabelsToSelector(labels []Label)
.
So I can do something like this
labels := []Label{
{
Key: "app.kubernetes.io/managed-by",
Operand: NotEqual,
Value: "odo"
}
}
ConvertLabelsToSelector(labels)
The conversion of []Label
to string
would also become simplified
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 would allow for room for extension and also less mistakes
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 seems to me as if this will require a significant amount of effort and it seems a little out of scope for this PR. Is it alright if I take this in another PR?
Also, can you give me an example of possible mistakes that could happen here?
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 you change strings.Replace(v, "!", "", -1)
to strings.Replace(v, "!", "", 1)
wouldn't it the problem of doing !!odo
?
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 am not sure I understand your problem question correctly.
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 am good from my end, please address @kadel's question and then remove the hold
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.
Just realized something. !
can't be present in a label or its value.
I think that we are ok with this. front.
But I think that I'm really missing here is a unit test for this function :-( It became much more complicated than it used to be, and it definetly deserves unit 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.
@kadel Unit tests! That can be easily fixed! I'll get to it.
@girishramnani I looked at how k8s.io/apimachinery does this label selector thing and it is a little complicated, they have special interface and methods for it. See here - https://github.com/openshift/odo/blob/89ac67e425bffe8c400645bca933d687b5ac8b19/vendor/k8s.io/apimachinery/pkg/fields/selector.go#L430
I will rely on Unit tests for now, and hopefully we will not run into corner cases, or catch them if we do.
tested, it it looks good |
/test v4.7-integration-e2e The failing test passes locally. Retrying. |
/hold |
/retest |
/unhold |
/override ci/prow/psi-unit-test-mac Reason - These are optional checks. |
@valaparthvi: Overrode contexts on behalf of valaparthvi: ci/prow/psi-unit-test-mac, ci/prow/psi-unit-test-windows In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: girishramnani, kadel The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@@ -2684,3 +2684,48 @@ func TestGetGitOriginPath(t *testing.T) { | |||
}) | |||
} | |||
} | |||
|
|||
func TestConvertLabelsToSelector(t *testing.T) { |
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.
❤️
/retest Please review the full test history for this PR and help us cut down flakes. |
1 similar comment
/retest Please review the full test history for this PR and help us cut down flakes. |
What type of PR is this?
/kind feature
/kind code-refactoring
What does this PR do / why we need it:
This PR adds the support to see components created/managed by tools other than odo.
Which issue(s) this PR fixes:
Fixes #4688
PR acceptance criteria:
Unit test
Integration test
Documentation
Update changelog
I have read the test guidelines
How to test changes / Special notes to the reviewer:
Manually create a deployment and deploymentconfig in openshift web console or any other tool. Make sure it is labelled with the following labels -
Or better yet, it follows these labels - https://github.com/redhat-developer/app-labels
With OCP4, it will be easy to create a component of a deployment kind by using the samples provided by ocp, but to create a deploymentConfig kind component you can use the following yaml -
Also create a few components with the help of odo.
Run
odo list
and you should be able to see the non-odo components in the output that looks something like this -Also, do test with
odo list --app sample-app
,odo list --all-apps -o json
,odo list
.Note - This is work-in-progress and you might find some commented code and incomplete tests, I am yet to add unit and integrations tests as well, but I am waiting on it to make sure that everyone agrees on the implmentation.