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 #257

Closed
wants to merge 25 commits into from
Closed
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
84426da
Add a register.go file to v1alpha1 types, and remove old deepcopy-gen…
luxas Jul 2, 2020
9eb482f
Add a common scheme package
luxas Jul 2, 2020
1b356dd
Remove unused NewScheme function and add comment to investigate
luxas Jul 2, 2020
aa6c762
Remove unused file
luxas Jul 2, 2020
8bac622
Use our new scheme package in the controller
luxas Jul 2, 2020
6d21f42
Don't register any types into the client-go scheme
luxas Jul 2, 2020
64d5147
Remove unused code and use our scheme instead of client-go
luxas Jul 2, 2020
e493033
Use the libgitops serializer
luxas Jul 2, 2020
0623e8e
Add libgitops import to go.mod
luxas Jul 2, 2020
f249e71
fix problems in unit tests, e.g. YAML indentatation errors
luxas Jul 2, 2020
f85feed
remove unused function
luxas Jul 2, 2020
d0ca2be
Merge branch 'master' into libgitops_serializer_v2
luxas Jul 16, 2020
05eaf54
Rewrite the manifest parsing to use kyaml & libgitops
luxas Jul 16, 2020
75842a3
update references to WithManifest
luxas Jul 16, 2020
0e544ba
Use WriteFrameList instead of yaml.Concat
luxas Jul 16, 2020
dc5d37a
go mod tidy
luxas Jul 16, 2020
64a17a7
Minor review comments. Use the serializer-embedded codecs and documen…
luxas Jul 16, 2020
bfcf2a7
add double quotes to test data, as output is in JSON
luxas Jul 16, 2020
3987e9e
Special handling for namespaces
luxas Jul 16, 2020
2d2b7ff
Add quotes to the JSON matching test code
luxas Jul 16, 2020
c906fbc
Make .spec.sshKeyPath optional
luxas Jul 16, 2020
10908cd
remove unnecessary quotes
luxas Jul 16, 2020
bac4bdf
Fix YAML indentation
luxas Jul 17, 2020
34cd206
Maybe now this is actually building YAML manifests...
luxas Jul 17, 2020
0b6bcfe
YAML indentation, part 1000
luxas Jul 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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 @@ -7,11 +7,10 @@ import (

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/weaveworks/wksctl/pkg/apis/baremetal/scheme"
wks "github.com/weaveworks/wksctl/pkg/apis/wksprovider/controller/wksctl"
baremetalv1 "github.com/weaveworks/wksctl/pkg/baremetal/v1alpha3"
machineutil "github.com/weaveworks/wksctl/pkg/cluster/machine"
"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 := baremetalv1.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"
baremetalv1 "github.com/weaveworks/wksctl/pkg/baremetal/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 := baremetalv1.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_baremetalclusters.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.1
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 @@ -49,6 +47,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.4.1
sigs.k8s.io/yaml v1.2.0
)

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

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions pkg/addons/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,18 +333,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(string(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.

40 changes: 40 additions & 0 deletions pkg/apis/baremetal/scheme/scheme.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package scheme

import (
ssv1alpha1 "github.com/bitnami-labs/sealed-secrets/pkg/apis/sealed-secrets/v1alpha1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/errors"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
clusterv1alpha3 "sigs.k8s.io/cluster-api/api/v1alpha3"

"github.com/weaveworks/libgitops/pkg/serializer"
"github.com/weaveworks/wksctl/pkg/baremetal/v1alpha3"
"github.com/weaveworks/wksctl/pkg/baremetalproviderspec/v1alpha1"
)

var (
// Scheme contains information about all known types, API versions, and defaulting & conversion methods
Scheme = runtime.NewScheme()

// Serializer provides powerful high-level encoding/decoding functionality
Serializer = serializer.NewSerializer(Scheme, nil)
)

func init() {
utilruntime.Must(AddToScheme(Scheme))
}

// AddToScheme builds the scheme using all known versions of the api.
func AddToScheme(scheme *runtime.Scheme) error {
// This returns an error if and only if any of the following function calls return an error
// If many errors are returned, they are all concatenated after each other
return errors.NewAggregate([]error{
clientgoscheme.AddToScheme(scheme), // Register all known Kubernetes types
ssv1alpha1.AddToScheme(scheme), // Register Bitnami's Sealed Secrets types
v1alpha1.AddToScheme(scheme), // Register our old v1alpha1 types
v1alpha3.AddToScheme(scheme), // Register our new v1alpha3 types
clusterv1alpha3.AddToScheme(scheme), // Register the upstream CAPI v1alpha3 types
scheme.SetVersionPriority(v1alpha3.SchemeGroupVersion), // Always prefer v1alpha3 when encoding our types
})
}
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.

Loading