-
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
Changes from all commits
653690b
2314fbc
723b2f6
4fa5c7b
145c108
0a6b4a4
9c877b1
c08b01d
7b36d6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
entries: | ||
- description: Add sdk annotations to bundle resources (CSVs, `annotations.yaml` and `bundle.dockerfile`). | ||
kind: "addition" |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,14 +16,18 @@ package registry | |||||
|
||||||
import ( | ||||||
"fmt" | ||||||
"io/ioutil" | ||||||
"os" | ||||||
|
||||||
apimanifests "github.com/operator-framework/api/pkg/manifests" | ||||||
apivalidation "github.com/operator-framework/api/pkg/validation" | ||||||
apierrors "github.com/operator-framework/api/pkg/validation/errors" | ||||||
registrybundle "github.com/operator-framework/operator-registry/pkg/lib/bundle" | ||||||
log "github.com/sirupsen/logrus" | ||||||
varshaprasad96 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
"gopkg.in/yaml.v2" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Switching over to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are trying to remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The operator-registry is still using
This comment was marked as outdated.
Sorry, something went wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The unit tests do pass with To reproduce the scenario:
The error which we get would be: Cause of error:
Now during unmarshalling, ie here, it would not be able to interpret this yaml because it has the key If we use 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 commentThe 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
Then, see that also it will work with 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. This could likely be fixed by adding 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 commentThe 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. |
||||||
k8svalidation "k8s.io/apimachinery/pkg/api/validation" | ||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||
|
||||||
"k8s.io/apimachinery/pkg/util/validation/field" | ||||||
) | ||||||
|
||||||
|
@@ -127,3 +131,59 @@ func appendResult(results []apierrors.ManifestResult, r apierrors.ManifestResult | |||||
|
||||||
return results | ||||||
} | ||||||
|
||||||
// RewriteAnnotationsYaml unmarshalls the specified yaml file, appends the content and | ||||||
// converts it again to yaml. | ||||||
func RewriteAnnotationsYaml(filename string, content map[string]string) error { | ||||||
|
||||||
metadata, err := getAnnotationFileContents(filename) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
// Append the contents to annotationsYaml | ||||||
for key, val := range content { | ||||||
metadata.Annotations[key] = val | ||||||
} | ||||||
|
||||||
err = writeAnnotationFile(filename, metadata) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
return nil | ||||||
} | ||||||
|
||||||
func getAnnotationFileContents(filename string) (*registrybundle.AnnotationMetadata, error) { | ||||||
f, err := ioutil.ReadFile(filename) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
|
||||||
annotationsYaml := ®istrybundle.AnnotationMetadata{} | ||||||
if err := yaml.Unmarshal(f, annotationsYaml); err != nil { | ||||||
return nil, fmt.Errorf("error parsing annotations file: %v", err) | ||||||
} | ||||||
return annotationsYaml, nil | ||||||
} | ||||||
|
||||||
func writeAnnotationFile(filename string, annotation *registrybundle.AnnotationMetadata) error { | ||||||
// TODO: replace `gopkg.in/yaml.v2` with `sigs.k8s.io/yaml`. Operator registry | ||||||
// defines annotations with yaml format (using gopkg-yaml) and k8s-yaml takes name | ||||||
// of field in the struct as the value of key in yaml. | ||||||
file, err := yaml.Marshal(annotation) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
mode := os.FileMode(0666) | ||||||
if info, err := os.Stat(filename); err == nil { | ||||||
mode = info.Mode() | ||||||
} | ||||||
|
||||||
err = ioutil.WriteFile(filename, []byte(file), mode) | ||||||
if err != nil { | ||||||
return fmt.Errorf("error writing modified contents to annotations file, %v", err) | ||||||
} | ||||||
return nil | ||||||
} |
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 alsogenerate 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 commandscreate/generate
) and wouldn't rewriting both of them together in a clean state be a better option in such a scenario?