Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

Use the generic Serializer in libgitops, and fix some API machinery nits #273

Merged
merged 25 commits into from Aug 3, 2020

Conversation

luxas
Copy link
Contributor

@luxas luxas commented Jul 17, 2020

This is a duplicate of #257, just created as a branch on this project instead of on my personal fork in order to run end-to-end tests.

@palemtnrider
Copy link
Contributor

I see some additional baremetal files being added here. What's the plan for moving from BareMetal to ExistingInfra?

Signed-off-by: Dennis Marttinen <dennis@weave.works>
Signed-off-by: Dennis Marttinen <dennis@weave.works>
@twelho
Copy link
Contributor

twelho commented Jul 31, 2020

@palemtnrider this was written before the ExistingInfra* refactor, but I've now rebased it on top of master with #224 merged. It should begin passing tests again, @luxas you could have one more look through it to make sure the rebase moved over all your intended changes.

Copy link
Contributor Author

@luxas luxas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the rebase 💯

@@ -9,9 +9,8 @@ import (
"github.com/spf13/cobra"
wks "github.com/weaveworks/wksctl/pkg/apis/wksprovider/controller/wksctl"
machineutil "github.com/weaveworks/wksctl/pkg/cluster/machine"
existinginfrav1 "github.com/weaveworks/wksctl/pkg/existinginfra/v1alpha3"
"github.com/weaveworks/wksctl/pkg/scheme"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe for later, but I'd move this to either github.com/weaveworks/wksctl/api/scheme or github.com/weaveworks/wksctl/pkg/apis/existinginfra/scheme.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The scheme pulls in both pkg/baremetalproviderspec/v1alpha1 and pkg/existinginfra/v1alpha3, so it's fine to keep it under pkg until we get pkg/apis re-organized.

Copy link
Contributor

@bboreham bboreham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm; couple of nits.

// In the future, if we wish to support other kinds of secrets than SealedSecrets, we
// can just change this to do .Decode(fr), and switch on the type
if err := scheme.Serializer.Decoder().DecodeInto(fr, ss); err != nil {
return nil, nil, "", nil, errors.Wrapf(err, "File %q does not contain a sealed secret, couldn't decode", secretFileName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible this error is something simpler, like bad indentation?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, changed the error message to be more generic.

}
func Parse(rc io.ReadCloser) (ml []*clusterv1.Machine, bl []*existinginfrav1.ExistingInfraMachine, err error) {
// Read from the ReadCloser YAML document-by-document
fr := serializer.NewYAMLFrameReader(rc)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's no longer necessary to close the reader?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FrameReader will close the reader when all elements have been read (when DecodeAll is called). Due to a libgitops bug (weaveworks/libgitops#33) if decoding fails for some reason the reader is currently left open, that needs to be fixed over there (not a blocker for this PR).

var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: GroupVersion}
var SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
var AddToScheme = SchemeBuilder.AddToScheme
func WithNamespace(fileOrString, namespace string) ([]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changed in this PR, but fileOrString seems weird : it's only used as a filename in one place, but in several other places what is passed in is the result from ioutil.ReadAll(). Anyway it could easily be two functions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use io.ReadCloser in faf7480, this removes redundant conversions and enables quite smooth usage with both files and bytes.

Signed-off-by: Dennis Marttinen <dennis@weave.works>
…ithNamespace

Signed-off-by: Dennis Marttinen <dennis@weave.works>
@bboreham bboreham merged commit f3623db into master Aug 3, 2020
@bboreham bboreham deleted the libgitops_serializer_v2 branch August 3, 2020 14:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants