Skip to content

Commit

Permalink
Splitting GCEProviderConfig into GCEClusterProviderConfig and GCEMach…
Browse files Browse the repository at this point in the history
…ineProviderConfig (kubernetes-sigs#183)
  • Loading branch information
mkjelland authored and k8s-ci-robot committed May 25, 2018
1 parent 2461d32 commit 9545eb3
Show file tree
Hide file tree
Showing 25 changed files with 330 additions and 213 deletions.
2 changes: 1 addition & 1 deletion cloud/google/cmd/gce-machine-controller/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ GCR_BUCKET = k8s-cluster-api
PREFIX = gcr.io/$(GCR_BUCKET)
DEV_PREFIX ?= gcr.io/$(shell gcloud config get-value project)
NAME = gce-machine-controller
TAG = 0.0.9
TAG = 0.0.10

image:
docker build -t "$(PREFIX)/$(NAME):$(TAG)" -f ./Dockerfile ../../../..
Expand Down
5 changes: 4 additions & 1 deletion cloud/google/gceproviderconfig/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ func Resource(resource string) schema.GroupResource {

func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&GCEProviderConfig{},
&GCEMachineProviderConfig{},
)
scheme.AddKnownTypes(SchemeGroupVersion,
&GCEClusterProviderConfig{},
)
return nil
}
10 changes: 8 additions & 2 deletions cloud/google/gceproviderconfig/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ import (
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type GCEProviderConfig struct {
type GCEMachineProviderConfig struct {
metav1.TypeMeta `json:",inline"`

Project string `json:"project"`
Zone string `json:"zone"`
MachineType string `json:"machineType"`

Expand All @@ -41,3 +40,10 @@ type DiskInitializeParams struct {
DiskSizeGb int64 `json:"diskSizeGb"`
DiskType string `json:"diskType"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type GCEClusterProviderConfig struct {
metav1.TypeMeta `json:",inline"`

Project string `json:"project"`
}
31 changes: 13 additions & 18 deletions cloud/google/gceproviderconfig/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -47,7 +44,10 @@ func init() {

func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&GCEProviderConfig{},
&GCEMachineProviderConfig{},
)
scheme.AddKnownTypes(SchemeGroupVersion,
&GCEClusterProviderConfig{},
)
return nil
}
Expand Down Expand Up @@ -80,27 +80,22 @@ func NewCodec() (*GCEProviderConfigCodec, error) {
return &codec, nil
}

func (codec *GCEProviderConfigCodec) DecodeFromProviderConfig(providerConfig clusterv1.ProviderConfig) (*GCEProviderConfig, error) {
obj, gvk, err := codec.decoder.Decode(providerConfig.Value.Raw, nil, nil)
func (codec *GCEProviderConfigCodec) DecodeFromProviderConfig(providerConfig clusterv1.ProviderConfig, out runtime.Object) (error) {
_, _, err := codec.decoder.Decode(providerConfig.Value.Raw, nil, out)
if err != nil {
return nil, fmt.Errorf("decoding failure: %v", err)
return fmt.Errorf("decoding failure: %v", err)
}
config, ok := obj.(*GCEProviderConfig)
if !ok {
return nil, fmt.Errorf("failure to cast to gce; type: %v", gvk)
}
return config, nil
return nil
}

func (codec *GCEProviderConfigCodec) EncodeToProviderConfig(gceProviderConfig *GCEProviderConfig) (*clusterv1.ProviderConfig, error) {
func (codec *GCEProviderConfigCodec) EncodeToProviderConfig(in runtime.Object) (*clusterv1.ProviderConfig, error) {
var buf bytes.Buffer
if err := codec.encoder.Encode(gceProviderConfig, &buf); err != nil {
if err := codec.encoder.Encode(in, &buf); err != nil {
return nil, fmt.Errorf("encoding failed: %v", err)
}
providerConfig := clusterv1.ProviderConfig{
return &clusterv1.ProviderConfig{
Value: &runtime.RawExtension{Raw: buf.Bytes()},
}
return &providerConfig, nil
}, nil
}

func newEncoder(codecFactory *serializer.CodecFactory) (runtime.Encoder, error) {
Expand All @@ -110,4 +105,4 @@ func newEncoder(codecFactory *serializer.CodecFactory) (runtime.Encoder, error)
}
encoder := codecFactory.EncoderForVersion(serializerInfos[0].Serializer, SchemeGroupVersion)
return encoder, nil
}
}
11 changes: 9 additions & 2 deletions cloud/google/gceproviderconfig/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ import (
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type GCEProviderConfig struct {
type GCEMachineProviderConfig struct {
metav1.TypeMeta `json:",inline"`

Project string `json:"project"`
Zone string `json:"zone"`
MachineType string `json:"machineType"`

Expand All @@ -41,3 +40,11 @@ type DiskInitializeParams struct {
DiskSizeGb int64 `json:"diskSizeGb"`
DiskType string `json:"diskType"`
}


// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type GCEClusterProviderConfig struct {
metav1.TypeMeta `json:",inline"`

Project string `json:"project"`
}
40 changes: 32 additions & 8 deletions cloud/google/gceproviderconfig/v1alpha1/zz_generated.deepcopy.go

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

40 changes: 32 additions & 8 deletions cloud/google/gceproviderconfig/zz_generated.deepcopy.go

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

Loading

0 comments on commit 9545eb3

Please sign in to comment.