Skip to content

Commit

Permalink
Update Ark library code to work with Kubernetes 1.11
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Arpaia <mike@arpaia.co>
  • Loading branch information
marpaia committed Jul 17, 2018
1 parent eabef08 commit 3efe677
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 34 deletions.
5 changes: 0 additions & 5 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@
name = "github.com/Azure/azure-sdk-for-go"
version = "~10.2.1-beta"

[[constraint]]
name = "github.com/Azure/go-autorest"
version = "~8.1.x"


[[constraint]]
name = "cloud.google.com/go"
version = "0.11.0"
Expand Down
4 changes: 2 additions & 2 deletions hack/build-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ FROM golang:1.10-alpine3.7
RUN apk add --update --no-cache git bash && \
mkdir -p /go/src/k8s.io && \
cd /go/src/k8s.io && \
git clone -b kubernetes-1.10.0 https://github.com/kubernetes/code-generator && \
git clone -b kubernetes-1.10.0 https://github.com/kubernetes/apimachinery && \
git clone -b kubernetes-1.11.0 https://github.com/kubernetes/code-generator && \
git clone -b kubernetes-1.11.0 https://github.com/kubernetes/apimachinery && \
echo chmod -R a+w /go
17 changes: 4 additions & 13 deletions pkg/client/dynamic.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
package client

import (
"github.com/pkg/errors"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
Expand All @@ -38,24 +36,17 @@ type DynamicFactory interface {

// dynamicFactory implements DynamicFactory.
type dynamicFactory struct {
clientPool dynamic.ClientPool
dynamicClient dynamic.Interface
}

// NewDynamicFactory returns a new ClientPool-based dynamic factory.
func NewDynamicFactory(clientPool dynamic.ClientPool) DynamicFactory {
return &dynamicFactory{clientPool: clientPool}
func NewDynamicFactory(dynamicClient dynamic.Interface) DynamicFactory {
return &dynamicFactory{dynamicClient: dynamicClient}
}

func (f *dynamicFactory) ClientForGroupVersionResource(gv schema.GroupVersion, resource metav1.APIResource, namespace string) (Dynamic, error) {
// client-go doesn't actually use the kind when getting the dynamic client from the client pool;
// it only needs the group and version.
dynamicClient, err := f.clientPool.ClientForGroupVersionKind(gv.WithKind(""))
if err != nil {
return nil, errors.Wrapf(err, "error getting client for GroupVersion %s, Resource %s", gv.String, resource.String())
}

return &dynamicResourceClient{
resourceClient: dynamicClient.Resource(&resource, namespace),
resourceClient: f.dynamicClient.Resource(gv.WithResource(resource.Name)).Namespace(namespace),
}, nil
}

Expand Down
8 changes: 6 additions & 2 deletions pkg/cloudprovider/aws/block_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import (
func TestGetVolumeID(t *testing.T) {
b := &blockStore{}

pv := &unstructured.Unstructured{}
pv := &unstructured.Unstructured{
Object: map[string]interface{}{},
}

// missing spec.awsElasticBlockStore -> no error
volumeID, err := b.GetVolumeID(pv)
Expand Down Expand Up @@ -69,7 +71,9 @@ func TestGetVolumeID(t *testing.T) {
func TestSetVolumeID(t *testing.T) {
b := &blockStore{}

pv := &unstructured.Unstructured{}
pv := &unstructured.Unstructured{
Object: map[string]interface{}{},
}

// missing spec.awsElasticBlockStore -> error
updatedPV, err := b.SetVolumeID(pv, "vol-updated")
Expand Down
8 changes: 6 additions & 2 deletions pkg/cloudprovider/azure/block_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import (
func TestGetVolumeID(t *testing.T) {
b := &blockStore{}

pv := &unstructured.Unstructured{}
pv := &unstructured.Unstructured{
Object: map[string]interface{}{},
}

// missing spec.azureDisk -> no error
volumeID, err := b.GetVolumeID(pv)
Expand Down Expand Up @@ -58,7 +60,9 @@ func TestSetVolumeID(t *testing.T) {
subscription: "sub",
}

pv := &unstructured.Unstructured{}
pv := &unstructured.Unstructured{
Object: map[string]interface{}{},
}

// missing spec.azureDisk -> error
updatedPV, err := b.SetVolumeID(pv, "updated")
Expand Down
8 changes: 6 additions & 2 deletions pkg/cloudprovider/gcp/block_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ import (
func TestGetVolumeID(t *testing.T) {
b := &blockStore{}

pv := &unstructured.Unstructured{}
pv := &unstructured.Unstructured{
Object: map[string]interface{}{},
}

// missing spec.gcePersistentDisk -> no error
volumeID, err := b.GetVolumeID(pv)
Expand All @@ -58,7 +60,9 @@ func TestGetVolumeID(t *testing.T) {
func TestSetVolumeID(t *testing.T) {
b := &blockStore{}

pv := &unstructured.Unstructured{}
pv := &unstructured.Unstructured{
Object: map[string]interface{}{},
}

// missing spec.gcePersistentDisk -> error
updatedPV, err := b.SetVolumeID(pv, "abc123")
Expand Down
13 changes: 9 additions & 4 deletions pkg/cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ type server struct {
backupService cloudprovider.BackupService
snapshotService cloudprovider.SnapshotService
discoveryClient discovery.DiscoveryInterface
clientPool dynamic.ClientPool
dynamicClient dynamic.Interface
sharedInformerFactory informers.SharedInformerFactory
ctx context.Context
cancelFunc context.CancelFunc
Expand Down Expand Up @@ -182,6 +182,11 @@ func newServer(namespace, baseName, pluginDir, metricsAddr string, logger *logru
return nil, err
}

dynamicClient, err := dynamic.NewForConfig(clientConfig)
if err != nil {
return nil, err
}

ctx, cancelFunc := context.WithCancel(context.Background())

s := &server{
Expand All @@ -191,7 +196,7 @@ func newServer(namespace, baseName, pluginDir, metricsAddr string, logger *logru
kubeClient: kubeClient,
arkClient: arkClient,
discoveryClient: arkClient.Discovery(),
clientPool: dynamic.NewDynamicClientPool(clientConfig),
dynamicClient: dynamicClient,
sharedInformerFactory: informers.NewFilteredSharedInformerFactory(arkClient, 0, namespace, nil),
ctx: ctx,
cancelFunc: cancelFunc,
Expand Down Expand Up @@ -562,7 +567,7 @@ func (s *server) runControllers(config *api.Config) error {

backupper, err := backup.NewKubernetesBackupper(
discoveryHelper,
client.NewDynamicFactory(s.clientPool),
client.NewDynamicFactory(s.dynamicClient),
podexec.NewPodCommandExecutor(s.kubeClientConfig, s.kubeClient.CoreV1().RESTClient()),
s.snapshotService,
s.resticManager,
Expand Down Expand Up @@ -638,7 +643,7 @@ func (s *server) runControllers(config *api.Config) error {

restorer, err := restore.NewKubernetesRestorer(
discoveryHelper,
client.NewDynamicFactory(s.clientPool),
client.NewDynamicFactory(s.dynamicClient),
s.backupService,
s.snapshotService,
config.ResourcePriorities,
Expand Down
1 change: 0 additions & 1 deletion pkg/cmd/util/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ func NewPrinter(cmd *cobra.Command) (*printers.HumanReadablePrinter, error) {
}

printer := printers.NewHumanReadablePrinter(
nil, // encoder, only needed if we want/need to convert unstructured/unknown to typed objects
nil, // decoder, only needed if we want/need to convert unstructured/unknown to typed objects
options,
)
Expand Down
6 changes: 3 additions & 3 deletions pkg/discovery/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/discovery"
"k8s.io/client-go/dynamic"
"k8s.io/client-go/restmapper"
)

// Helper exposes functions for interacting with the Kubernetes discovery
Expand Down Expand Up @@ -91,11 +91,11 @@ func (h *helper) Refresh() error {
h.lock.Lock()
defer h.lock.Unlock()

groupResources, err := discovery.GetAPIGroupResources(h.discoveryClient)
groupResources, err := restmapper.GetAPIGroupResources(h.discoveryClient)
if err != nil {
return errors.WithStack(err)
}
mapper := discovery.NewRESTMapper(groupResources, dynamic.VersionInterfaces)
mapper := restmapper.NewDiscoveryRESTMapper(groupResources)
shortcutExpander, err := kcmdutil.NewShortcutExpander(mapper, h.discoveryClient, h.logger)
if err != nil {
return errors.WithStack(err)
Expand Down

0 comments on commit 3efe677

Please sign in to comment.