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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a18b48d
Add a register.go file to v1alpha1 types, and remove old deepcopy-gen…
luxas Jul 2, 2020
1bc8e77
Add a common scheme package
luxas Jul 2, 2020
63eaee3
Remove unused NewScheme function and add comment to investigate
luxas Jul 2, 2020
9150f36
Remove unused file
luxas Jul 2, 2020
41856d1
Use our new scheme package in the controller
luxas Jul 2, 2020
8f39136
Don't register any types into the client-go scheme
luxas Jul 2, 2020
0d18f23
Remove unused code and use our scheme instead of client-go
luxas Jul 2, 2020
40fd12b
Use the libgitops serializer
luxas Jul 2, 2020
bfc899f
fix problems in unit tests, e.g. YAML indentatation errors
luxas Jul 2, 2020
7c14009
Rewrite the manifest parsing to use kyaml & libgitops
luxas Jul 16, 2020
b247dc7
update references to WithManifest
luxas Jul 16, 2020
9b6cd27
Use WriteFrameList instead of yaml.Concat
luxas Jul 16, 2020
325ec9e
Minor review comments. Use the serializer-embedded codecs and documen…
luxas Jul 16, 2020
64e9673
add double quotes to test data, as output is in JSON
luxas Jul 16, 2020
060bf57
Special handling for namespaces
luxas Jul 16, 2020
c6ab293
Add quotes to the JSON matching test code
luxas Jul 16, 2020
866cfcd
Make .spec.sshKeyPath optional
luxas Jul 16, 2020
62b0846
remove unnecessary quotes
luxas Jul 16, 2020
0557f31
Fix YAML indentation
luxas Jul 17, 2020
2a4613e
Maybe now this is actually building YAML manifests...
luxas Jul 17, 2020
c40e686
YAML indentation, part 1000
luxas Jul 17, 2020
bcd0c42
Move scheme to pkg, fix imports, remove unnecessary AddToScheme calls
twelho Jul 31, 2020
9947512
Remove deprecated register option for deepcopy-gen in v1alpha3
twelho Jul 31, 2020
9ba0b10
Generalize error message when decoding sealed secrets
twelho Aug 3, 2020
faf7480
Avoid redundant conversions by passing an io.ReadCloser to manifest.W…
twelho Aug 3, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 5 additions & 11 deletions cmd/controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.

"k8s.io/client-go/kubernetes"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand Down Expand Up @@ -85,19 +84,14 @@ func run(cmd *cobra.Command, args []string) {
if err != nil {
log.Fatalf("failed to create Kubernetes client set: %v", err)
}
mgr, err := manager.New(cfg, manager.Options{})
mgr, err := manager.New(cfg, manager.Options{
// Use our own Scheme here with our known types, and the client-go k8s ones
Scheme: scheme.Scheme,
})
if err != nil {
log.Fatalf("failed to create the cluster manager: %v", err)
}

log.Info("registering scheme for all resources")
if err := existinginfrav1.AddToScheme(mgr.GetScheme()); err != nil {
log.Fatal(err)
}
if err := clusterv1.AddToScheme(mgr.GetScheme()); err != nil {
log.Fatal(err)
}

log.Info("registering controllers to the cluster manager")
clusterReconciler, err := wks.NewClusterReconciler(mgr.GetClient(), mgr.GetEventRecorderFor(wks.ProviderName+"-controller"))
if err != nil {
Expand Down
10 changes: 0 additions & 10 deletions cmd/wksctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/weaveworks/go-checkpoint"
"k8s.io/client-go/kubernetes/scheme"
clusterv1 "sigs.k8s.io/cluster-api/api/v1alpha3"

"github.com/weaveworks/wksctl/cmd/wksctl/addon"
"github.com/weaveworks/wksctl/cmd/wksctl/apply"
Expand All @@ -20,7 +18,6 @@ import (
"github.com/weaveworks/wksctl/cmd/wksctl/registrysynccommands"
"github.com/weaveworks/wksctl/cmd/wksctl/version"
"github.com/weaveworks/wksctl/cmd/wksctl/zshcompletions"
existinginfrav1 "github.com/weaveworks/wksctl/pkg/existinginfra/v1alpha3"
v "github.com/weaveworks/wksctl/pkg/version"
)

Expand All @@ -45,13 +42,6 @@ func configureLogger(cmd *cobra.Command, args []string) {
}

func main() {
if err := clusterv1.AddToScheme(scheme.Scheme); err != nil {
log.Fatal(err)
}
if err := existinginfrav1.AddToScheme(scheme.Scheme); err != nil {
log.Fatal(err)
}

rootCmd.PersistentFlags().BoolVarP(&options.verbose, "verbose", "v", false, "Enable verbose output")

rootCmd.AddCommand(addon.Cmd)
Expand Down
1 change: 0 additions & 1 deletion config/crd/cluster.weave.works_existinginfraclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ spec:
type: string
required:
- cri
- sshKeyPath
- user
type: object
status:
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ require (
github.com/google/go-jsonnet v0.16.0
github.com/googleapis/gnostic v0.4.1 // indirect
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/oleiade/reflections v1.0.0 // indirect
github.com/pelletier/go-toml v1.8.0
github.com/pkg/errors v0.9.1
Expand All @@ -31,13 +29,13 @@ require (
github.com/weaveworks/footloose v0.0.0-20200609124411-8f3df89ea188
github.com/weaveworks/go-checkpoint v0.0.0-20170503165305-ebbb8b0518ab
github.com/weaveworks/launcher v0.0.0-20180824102238-59a4fcc32c9c
github.com/weaveworks/libgitops v0.0.2
github.com/whilp/git-urls v0.0.0-20191001220047-6db9661140c0
golang.org/x/crypto v0.0.0-20200707235045-ab33eee955e0
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae // indirect
golang.org/x/tools v0.0.0-20200708003708-134513de8882 // indirect
gomodules.xyz/jsonpatch/v2 v2.1.0 // indirect
google.golang.org/appengine v1.6.5 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/oleiade/reflections.v1 v1.0.0
gopkg.in/src-d/go-git.v4 v4.13.1
k8s.io/api v0.18.5
Expand All @@ -50,6 +48,7 @@ require (
k8s.io/utils v0.0.0-20200619165400-6e3d28b6ed19
sigs.k8s.io/cluster-api v0.3.6
sigs.k8s.io/controller-runtime v0.6.0
sigs.k8s.io/kustomize/kyaml v0.1.11
sigs.k8s.io/yaml v1.2.0
)

Expand Down
192 changes: 192 additions & 0 deletions go.sum

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions pkg/addons/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/ghodss/yaml"
"github.com/google/go-jsonnet"
log "github.com/sirupsen/logrus"
"github.com/weaveworks/libgitops/pkg/serializer"
"github.com/weaveworks/wksctl/pkg/addons/assets"
"github.com/weaveworks/wksctl/pkg/qjson"
"github.com/weaveworks/wksctl/pkg/registry"
Expand Down Expand Up @@ -333,18 +334,20 @@ func (a *Addon) buildJsonnet(config BuildOptions) ([]string, error) {
return nil, err
}

for filename, value := range output {
for filename, strValue := range output {
content := []byte(strValue)
if config.YAML {
data, err := yaml.JSONToYAML([]byte(value))
data, err := yaml.JSONToYAML(content)
if err != nil {
return nil, err
}
value, err = manifest.WithNamespace(string(data), "wkp-addons")
// The WithNamespace function supports either JSON or YAML
content, err = manifest.WithNamespace(serializer.FromBytes(data), "wkp-addons")
if err != nil {
return nil, err
}
}
if err := ioutil.WriteFile(filename, []byte(value), 0660); err != nil {
if err := ioutil.WriteFile(filename, content, 0660); err != nil {
return nil, err
}
}
Expand Down
17 changes: 0 additions & 17 deletions pkg/apis/apis.go

This file was deleted.

4 changes: 2 additions & 2 deletions pkg/apis/wksprovider/machine/crds/crds_vfsdata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.