-
Notifications
You must be signed in to change notification settings - Fork 10
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
Refactor and simplify structs (#2314) #20
Refactor and simplify structs (#2314) #20
Conversation
Changes to HAS are in this branch, excluding the go.mod file (just pull in the changes from this PR to see) |
Here is the commit (differences) in HAS: |
api/v1alpha1/component_types.go
Outdated
@@ -38,18 +39,11 @@ type GitSource struct { | |||
DockerfileURL string `json:"dockerfileUrl,omitempty"` |
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 there an order of precedence for component creation if the URL, DevfileURL, and DockerfileURLs are all specified at once? Should this be documented?
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.
Right now, they are placeholders. Those are currently not used by the Generator - only the URL is used.
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.
Based on your later review comments, I'll get rid of these.
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 don't know if this will break HAS. If these are HAS specific, then they belong in the HAS repo. They don't really fit the category of "git source" either. cc @maysunfaisal
api/v1alpha1/component_types.go
Outdated
@@ -62,103 +56,27 @@ type ComponentSpec struct { | |||
Secret string `json:"secret,omitempty"` | |||
|
|||
// Source describes the Component source | |||
Source ComponentSource `json:"source,omitempty"` | |||
Source *ComponentSource `json:"source,omitempty"` |
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.
how about
Source *ComponentSource `json:"source,omitempty"` | |
GitSource *GitSource `json:"gitSource,omitempty"` |
because ContainerImage
can also be a source. This would mean also renaming type ComponentSource struct{}
I am thinking about making this change in the application-service too after thinking about it now. it looks cleaner
4cf3290
to
11fa47f
Compare
Note that the definition of Resource is different in GitOps service and HAS: Managed GitOps Services HAS Both are used when generating the deployment file (deployment kind). I've changed it to be a non-pointer. See the component_types.go file. |
Here is the updated commit in HAS to reflect these changes |
11fa47f
to
315d3da
Compare
Here is the latest commit for the HAS repo to reflect these changes. A follow-on PR for that will be created including updating the go.mod file, etc. (It just has the source changes) |
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 a suggestion to change function param to
options
since we changed the struct name - pls have a look at my ENV suggestion for deployment patch func, is it valid?
api/v1alpha1/component_types.go
Outdated
type GitSource struct { | ||
// If importing from git, the repository to create the component from | ||
URL string `json:"url"` | ||
|
||
// Specify a branch/tag/commit id. If not specified, default is `main`/`master`. | ||
Revision string `json:"revision,omitempty"` | ||
//Revision string `json:"revision,omitempty"` |
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 think we might need to keep this
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.
These are not used anywhere in the source so far.
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 is used in the application-service
repo which will eventually rely on this code (see https://github.com/redhat-appstudio/application-service/blob/651fc2e107c413f88dc3796b581ef13e3387243c/controllers/component_controller.go#L210)
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.
That is application-service's original types. Note that a duplicate of these types (structs) were made in the common library to make the transition to the library easier. This duplicate or the 'mapping' now needs to be reduced because many of the fields are not necessary when generating the k8s resources. If you need any field added to the 'mapping', then that field must be used by the library in some way. Currently, what you see now in this PR are the fields that are used.
79f1b38
to
48d8f3f
Compare
I also renamed the file in api/v1alpha1 from |
Codecov ReportBase: 81.63% // Head: 80.67% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #20 +/- ##
==========================================
- Coverage 81.63% 80.67% -0.97%
==========================================
Files 6 6
Lines 588 595 +7
==========================================
Hits 480 480
- Misses 99 106 +7
Partials 9 9
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
48d8f3f
to
7b7ab8c
Compare
Here are the latest rebased changes to the application-service to react to these changes (minus the go.mod changes) |
7b7ab8c
to
336737c
Compare
Signed-off-by: Keith Chong <kykchong@redhat.com>
ee1f1ff
to
42a9ef1
Compare
Thanks for the review folks. We needed to rebase again. |
The initial HAS struct types were maintained. The goal now is to simplify, especially when the ComponentSpec configuration and the BindingComponentConfiguration have overlap. (They are both used primarily in the generation of the basic k8s deployment.yaml).
Each element in the BindingComponentConfiguration is mapped nicely to the ComponentSpec, except for Resources, where in the former, the ResourceRequirement is a pointer, but, in the latter, it is a non-pointer. This PR will use a non-pointer. Similarly, this reflects how it is done in k8s Container. See
https://github.com/kubernetes/api/blob/6dd661f592205cc6035520138ebdbd271b9fa197/core/v1/types.go#L2369
The goal is ‘flatten’ the structs and simplify, so the elements from ComponentSpec will be moved to the Component struct. The Source element will have the ComponentSource type however, and these types are flattened too. (There isn’t a need for multiple GitSources and Unions so this PR simplifies this.)
Mapping:
Original: component.Spec.Source.ComponentSourceUnion.GitSource, where GitSource is a pointer to GitSource
New: component.Source.ComponentSource, where Source is a pointer to ComponentSource
This is so that you can check for a nil ComponentSource. See the corresponding changes in the Application Service PR. This is similar to checking if component.Spec.Source.ComponentSourceUnion.GitSource != nil
Signed-off-by: Keith Chong kykchong@redhat.com