Skip to content

[WIP] ⚠️ Server Side Apply Support #366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
102 changes: 48 additions & 54 deletions Gopkg.lock

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

8 changes: 4 additions & 4 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ required = ["sigs.k8s.io/testing_frameworks/integration",

[[constraint]]
name = "k8s.io/api"
version = "kubernetes-1.13.4"
version = "kubernetes-1.14.0-rc.1"

[[constraint]]
name = "k8s.io/apiextensions-apiserver"
version = "kubernetes-1.13.4"
version = "kubernetes-1.14.0-rc.1"

[[constraint]]
name = "k8s.io/apimachinery"
version = "kubernetes-1.13.4"
version = "kubernetes-1.14.0-rc.1"

[[constraint]]
name = "k8s.io/client-go"
version = "kubernetes-1.13.4"
version = "kubernetes-1.14.0-rc.1"

[[constraint]]
name = "sigs.k8s.io/testing_frameworks"
Expand Down
57 changes: 57 additions & 0 deletions pkg/client/applier.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Copyright 2018 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.
See the License for the specific language governing permissions and
limitations under the License.
*/

package client

import (
"context"

"k8s.io/apimachinery/pkg/runtime"
)

// Applier declaratively ensures that objects match some particular
// configuration. It does this by using server-side apply.
// Each applier represents a different "concern" that owns a set of
// fields, so different reconcilers should generally have different
// appliers.
type Applier struct {
Name string
Writer
}

// InjectClient automatically receives a client, if desired.
func (a *Applier) InjectClient(cl Client) error {
a.Writer = cl
return nil
}

// Ensure makes sure that the given object is configured according
// to the configuration passed in (using server-side apply).
//
// To use Ensure, construct an object that has the fields set that
// this particular applier cares about. Fields and map elements that
// previously were set by this applier will be automatically removed
// if they're no longer present, new fields will be added, and existing
// ones updated.
//
// The server does this by keeping track of "ownership" of a particular
// field, and thus you should never call call client.Get and then Ensure.
func (a *Applier) Ensure(ctx context.Context, obj runtime.Object) error {
return a.Patch(ctx, obj, Apply, ForceOwnership, FieldManager(a.Name))
}

// TODO(directxman12): figure out a nice workflow for automatically populating
// this -- we could get name from the controller name, for instance.
8 changes: 8 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,11 @@ func (sw *statusWriter) Update(ctx context.Context, obj runtime.Object) error {
}
return sw.client.typedClient.UpdateStatus(ctx, obj)
}

func (sw *statusWriter) Patch(ctx context.Context, obj runtime.Object, patch Patch, opts ...PatchOptionFunc) error {
_, ok := obj.(*unstructured.Unstructured)
if ok {
return sw.client.unstructuredClient.PatchStatus(ctx, obj, patch, opts...)
}
return sw.client.typedClient.PatchStatus(ctx, obj, patch, opts...)
}
Loading