-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[sdk-stamps] add sdk stamps to bundle images #3120
[sdk-stamps] add sdk stamps to bundle images #3120
Conversation
@estroz @joelanford @jmrodri Would be helpful to have initial reviews |
cmd/operator-sdk/bundle/create.go
Outdated
return filepath.Join(filepath.Dir(manifestsDir), bundle.MetadataDir, bundle.AnnotationsFile) | ||
} | ||
|
||
func getSDKMetricsContent() map[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.
Added this function here so that it remains consistent by adding scorecard labels and metrics labels in create.go
d813f51
to
e86550a
Compare
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.
Initial review
e86550a
to
57bdc02
Compare
7f7752e
to
3f5c365
Compare
64bc768
to
c92d21b
Compare
internal/generate/clusterserviceversion/bases/clusterserviceversion.go
Outdated
Show resolved
Hide resolved
registrybundle "github.com/operator-framework/operator-registry/pkg/lib/bundle" | ||
log "github.com/sirupsen/logrus" | ||
"gopkg.in/yaml.v2" |
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.
"gopkg.in/yaml.v2" | |
"sigs.k8s.io/yaml" |
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.
Switching over to gopkg.in/yaml.v2
. k8s-yaml interprets and appends the name of the field defined in yaml struct while marshaling and unmarshaling, whereas gopkg-yaml uses the yaml annotation defined in the struct. Example - https://play.golang.org/p/uQ_J4oZBbCR
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 trying to remove the "gopkg.in/yaml.v2"
. See : #2790
So, we should not add new code with it.
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 operator-registry is still using gopkg.in/yaml.v2
for generation of annotation.yaml
. Here: https://github.com/operator-framework/operator-registry/blob/master/pkg/lib/bundle/generate.go#L12. And this function is trying to essentially replicate their process.
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
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 unit tests do pass with "sigs.k8s.io/yaml"
. However, it would fail in the scenario where we create bundle image using files already present on disk.
Explanation is as below:
To reproduce the scenario:
- First create bundle files on disk with
operator-sdk bundle create
command and--generate-only
flag. - Now create bundle image and push it to the registry (ie use the eg. command:
operator-sdk bundle create quay.io/example/memcached-operator:latest --directory path/to/manifests --package memcached-operator
)
The error which we get would be:
Unmatched number of fields. Expected 6 vs existing 0
. It fails here.
Cause of error:
When we use sigs.k8s.io/yaml
, the key in annotations.yaml
file would be the name of the field in AnnotationMetadata
struct. The annotations.yaml
which would be rewritten after adding the sdk stamps, would be like this:
Annotations:
operators.operatorframework.io.bundle.channel.default.v1: stable
operators.operatorframework.io.bundle.channels.v1: stable
operators.operatorframework.io.bundle.manifests.v1: manifests/
Now during unmarshalling, ie here, it would not be able to interpret this yaml because it has the key Annotations
not annotations
. The gopkg
at operator-registry expects the key in yaml file to be annotations
.
If we use "gopkg.in/yaml.v2"
, the annotations.yaml
which we re-write, would take the marker value (name of field) defined in yaml struct, yaml:"annotations"
as it does in operator-registry and it would unmarshall properly.
I have created a simple example to show the difference between both the packages in this playground: https://play.golang.org/p/uQ_J4oZBbCR
This scenario is being checked in one of the CI tests.
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.
See that your example will work if we replace the yaml for JSON
Something int
yaml:"somethingGreat,omitempty"
With
Something intjson:"somethingGreat,omitempty"
Then, see that also it will work with yaml
if we replace the Unmarshal/Marchal
for JSONToYAML/YAMLToJSON
. See: https://play.golang.org/p/D2guhgb7cvc
In SDK, we read/update/delete the files and use the lib to verify them. In this way, no matter the dep/lib that we use to manipulate it, all should work fine if at the end we have the same result. Then, I understand that if we change the impl here to use the above it should work.
However, if you still just facing problems with. could you please add a comment with a //todo: replace it for "sigs.k8s.io/yaml". Operator-registry defines the annotations with yaml 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.
Adding //todo: because of the dependency on operator-registry. OR defines annotations.
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 could likely be fixed by adding json:"annotations"
to the struct tag in the operator-registry repo.
So it would look like:
type AnnotationMetadata struct {
Annotations map[string]string `yaml:"annotations" json:"annotations"``
}
Obviously this would require an upstream PR to be merged and for us to update our dependency to a new commit/version, so we shouldn't block this PR for that.
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 continue with above and have an upstream PR in parallel. Ill have a follow-up PR to remove the TODO.
cd3ecd0
to
594bda2
Compare
06e58be
to
5509ab0
Compare
d0ad607
to
7a2313c
Compare
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.
A few minor changes required
internal/generate/clusterserviceversion/clusterserviceversion_test.go
Outdated
Show resolved
Hide resolved
internal/generate/clusterserviceversion/clusterserviceversion_test.go
Outdated
Show resolved
Hide resolved
eaca440
to
c0a166a
Compare
Add SDK related metric labels and annotations to bundle images
2e93e4e
to
3ee2066
Compare
3ee2066
to
7b36d6d
Compare
annotationsDir = outputDir + bundle.MetadataDir | ||
} | ||
|
||
if genutil.IsNotExist(bundle.DockerFile) || genutil.IsNotExist(annotationsDir) { |
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 make this check robust, you need to check and write to each file individually, since one may exist without the other.
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.
Yes, but I was thinking of rewriting both of them even if one exists, because until tweaked manually GenerateFunc
of OR is going to write both and also generate bundle
provides a --metadata
option which writes both. In the sense, if there is a scenario where only one of them exists, doesn't it mean that either it has been manually deleted or there is some error (though I assume its taken care of in respective commands create/generate
) and wouldn't rewriting both of them together in a clean state be a better option in such a scenario?
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.
/lgtm
Description of the change:
Add SDK related metric labels and annotations to bundle images
Motivation for the change:
To enable OLM track SDK Operators with help of these stamps on bundle resources.
Things to do:
generate csv
command)generate crds
command)Note:
Adding of labels to CRDs through controller-gen for new project layouts will be done in a new PR. Adding labels through built-in crd-gen for legacy layouts is removed from this PR as of now, and will be included in a follow up later.
Co-authored by: @estroz