* Feat: Removing Clientset to prepare for integration with fleet (#59)

* testing

* testing

* testing

* Updated makefile, brought back update-codegen to include deepcopy and register

* Update on e2e

* e2e works now

* lint fix

* removed all unnecessary prints

* undoing work

* undoing work - ci

* undoing work - unit-fix

* undoing work - unit-fix 2

* undoing work - e2e - 1

* undoing work - e2e - 2

Co-authored-by: Youn Jae Kim <younjaekim@microsoft.com>

* Fix:  Resolved conflict issues from master merge. (#64)

* Resolved conflicts with new e2e refactor and removal of ClientSet.

Co-authored-by: Youn Jae Kim <younjaekim@microsoft.com>
Co-authored-by: Sean Hobbs <sehobbs@microsoft.com>

* readding apply_controller_test.go

* readding apply_controller_test.go

* readding apply_controller_test.go

* increasing eventuallyTimeout to 30

* disabling code-cov for now

* editing threshold

* readding integration test.

* readding integration test.

* removed it

* removed it

Co-authored-by: Youn Jae Kim <younjaekim@microsoft.com>
Co-authored-by: Sean Hobbs <ealianis@outlook.com>
Co-authored-by: Sean Hobbs <sehobbs@microsoft.com>
This commit is contained in:
Youn Jae Kim 2022-07-15 18:11:47 -07:00 коммит произвёл GitHub
Родитель 5a362d0388
Коммит 622f2ac4e4
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
40 изменённых файлов: 154 добавлений и 2316 удалений

17
.github/workflows/ci.yml поставляемый
Просмотреть файл

@ -8,6 +8,7 @@ on:
branches:
- master
- release-*
- Feature/*
workflow_dispatch: {}
defaults:
@ -78,14 +79,14 @@ jobs:
env:
GOPATH: ${{ env.GO_PATH }}
- name: Upload report
uses: codecov/codecov-action@v3
with:
## Comma-separated list of files to upload
files: go/src/sigs.k8s.io/work-api/cover.out
flags: ci-tests
name: codecov-umbrella
fail_ci_if_error: true
# - name: Upload report
# uses: codecov/codecov-action@v3
# with:
# ## Comma-separated list of files to upload
# files: go/src/sigs.k8s.io/work-api/cover.out
# flags: ci-tests
# name: codecov-umbrella
# fail_ci_if_error: true
e2e:
name: e2e

Просмотреть файл

@ -10,7 +10,7 @@ rules:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: work-controller
name: work-controller-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole

2
go.mod
Просмотреть файл

@ -10,6 +10,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.0
k8s.io/api v0.23.0
k8s.io/apiextensions-apiserver v0.23.0
k8s.io/apimachinery v0.23.0
k8s.io/client-go v0.23.0
k8s.io/code-generator v0.23.0
@ -70,7 +71,6 @@ require (
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/apiextensions-apiserver v0.23.0 // indirect
k8s.io/component-base v0.23.0 // indirect
k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect

Просмотреть файл

@ -26,11 +26,8 @@ go install k8s.io/code-generator/cmd/{client-gen,lister-gen,informer-gen,deepcop
GOBIN="$(go env GOBIN)"
gobin="${GOBIN:-$(go env GOPATH)/bin}"
OUTPUT_PKG=sigs.k8s.io/work-api/pkg/client
FQ_APIS=sigs.k8s.io/work-api/pkg/apis/v1alpha1
APIS_PKG=sigs.k8s.io/work-api
CLIENTSET_NAME=versioned
CLIENTSET_PKG_NAME=clientset
if [[ "${VERIFY_CODEGEN:-}" == "true" ]]; then
echo "Running in verification mode"
@ -41,19 +38,5 @@ COMMON_FLAGS="${VERIFY_FLAG:-} --go-header-file ${SCRIPT_ROOT}/hack/boilerplate.
echo "Generating deepcopy funcs"
"${gobin}/deepcopy-gen" --input-dirs "${FQ_APIS}" -O zz_generated.deepcopy --bounding-dirs "${APIS_PKG}" ${COMMON_FLAGS}
echo "Generating clientset at ${OUTPUT_PKG}/${CLIENTSET_PKG_NAME}"
"${gobin}/client-gen" --clientset-name "${CLIENTSET_NAME}" --input-base "" --input "${FQ_APIS}" --output-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME}" ${COMMON_FLAGS}
echo "Generating listers at ${OUTPUT_PKG}/listers"
"${gobin}/lister-gen" --input-dirs "${FQ_APIS}" --output-package "${OUTPUT_PKG}/listers" ${COMMON_FLAGS}
echo "Generating informers at ${OUTPUT_PKG}/informers"
"${gobin}/informer-gen" \
--input-dirs "${FQ_APIS}" \
--versioned-clientset-package "${OUTPUT_PKG}/${CLIENTSET_PKG_NAME}/${CLIENTSET_NAME}" \
--listers-package "${OUTPUT_PKG}/listers" \
--output-package "${OUTPUT_PKG}/informers" \
${COMMON_FLAGS}
echo "Generating register at ${FQ_APIS}"
"${gobin}/register-gen" --output-package "${FQ_APIS}" --input-dirs ${FQ_APIS} ${COMMON_FLAGS}

Просмотреть файл

@ -1,97 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by client-gen. DO NOT EDIT.
package versioned
import (
"fmt"
discovery "k8s.io/client-go/discovery"
rest "k8s.io/client-go/rest"
flowcontrol "k8s.io/client-go/util/flowcontrol"
multiclusterv1alpha1 "sigs.k8s.io/work-api/pkg/client/clientset/versioned/typed/apis/v1alpha1"
)
type Interface interface {
Discovery() discovery.DiscoveryInterface
MulticlusterV1alpha1() multiclusterv1alpha1.MulticlusterV1alpha1Interface
}
// Clientset contains the clients for groups. Each group has exactly one
// version included in a Clientset.
type Clientset struct {
*discovery.DiscoveryClient
multiclusterV1alpha1 *multiclusterv1alpha1.MulticlusterV1alpha1Client
}
// MulticlusterV1alpha1 retrieves the MulticlusterV1alpha1Client
func (c *Clientset) MulticlusterV1alpha1() multiclusterv1alpha1.MulticlusterV1alpha1Interface {
return c.multiclusterV1alpha1
}
// Discovery retrieves the DiscoveryClient
func (c *Clientset) Discovery() discovery.DiscoveryInterface {
if c == nil {
return nil
}
return c.DiscoveryClient
}
// NewForConfig creates a new Clientset for the given config.
// If config's RateLimiter is not set and QPS and Burst are acceptable,
// NewForConfig will generate a rate-limiter in configShallowCopy.
func NewForConfig(c *rest.Config) (*Clientset, error) {
configShallowCopy := *c
if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 {
if configShallowCopy.Burst <= 0 {
return nil, fmt.Errorf("burst is required to be greater than 0 when RateLimiter is not set and QPS is set to greater than 0")
}
configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst)
}
var cs Clientset
var err error
cs.multiclusterV1alpha1, err = multiclusterv1alpha1.NewForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy)
if err != nil {
return nil, err
}
return &cs, nil
}
// NewForConfigOrDie creates a new Clientset for the given config and
// panics if there is an error in the config.
func NewForConfigOrDie(c *rest.Config) *Clientset {
var cs Clientset
cs.multiclusterV1alpha1 = multiclusterv1alpha1.NewForConfigOrDie(c)
cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c)
return &cs
}
// New creates a new Clientset for the given RESTClient.
func New(c rest.Interface) *Clientset {
var cs Clientset
cs.multiclusterV1alpha1 = multiclusterv1alpha1.New(c)
cs.DiscoveryClient = discovery.NewDiscoveryClient(c)
return &cs
}

Просмотреть файл

@ -1,20 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by client-gen. DO NOT EDIT.
// This package has the automatically generated clientset.
package versioned

Просмотреть файл

@ -1,85 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by client-gen. DO NOT EDIT.
package fake
import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/discovery"
fakediscovery "k8s.io/client-go/discovery/fake"
"k8s.io/client-go/testing"
clientset "sigs.k8s.io/work-api/pkg/client/clientset/versioned"
multiclusterv1alpha1 "sigs.k8s.io/work-api/pkg/client/clientset/versioned/typed/apis/v1alpha1"
fakemulticlusterv1alpha1 "sigs.k8s.io/work-api/pkg/client/clientset/versioned/typed/apis/v1alpha1/fake"
)
// NewSimpleClientset returns a clientset that will respond with the provided objects.
// It's backed by a very simple object tracker that processes creates, updates and deletions as-is,
// without applying any validations and/or defaults. It shouldn't be considered a replacement
// for a real clientset and is mostly useful in simple unit tests.
func NewSimpleClientset(objects ...runtime.Object) *Clientset {
o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder())
for _, obj := range objects {
if err := o.Add(obj); err != nil {
panic(err)
}
}
cs := &Clientset{tracker: o}
cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake}
cs.AddReactor("*", "*", testing.ObjectReaction(o))
cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) {
gvr := action.GetResource()
ns := action.GetNamespace()
watch, err := o.Watch(gvr, ns)
if err != nil {
return false, nil, err
}
return true, watch, nil
})
return cs
}
// Clientset implements clientset.Interface. Meant to be embedded into a
// struct to get a default implementation. This makes faking out just the method
// you want to test easier.
type Clientset struct {
testing.Fake
discovery *fakediscovery.FakeDiscovery
tracker testing.ObjectTracker
}
func (c *Clientset) Discovery() discovery.DiscoveryInterface {
return c.discovery
}
func (c *Clientset) Tracker() testing.ObjectTracker {
return c.tracker
}
var (
_ clientset.Interface = &Clientset{}
_ testing.FakeClient = &Clientset{}
)
// MulticlusterV1alpha1 retrieves the MulticlusterV1alpha1Client
func (c *Clientset) MulticlusterV1alpha1() multiclusterv1alpha1.MulticlusterV1alpha1Interface {
return &fakemulticlusterv1alpha1.FakeMulticlusterV1alpha1{Fake: &c.Fake}
}

Просмотреть файл

@ -1,20 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by client-gen. DO NOT EDIT.
// This package has the automatically generated fake clientset.
package fake

Просмотреть файл

@ -1,56 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by client-gen. DO NOT EDIT.
package fake
import (
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
schema "k8s.io/apimachinery/pkg/runtime/schema"
serializer "k8s.io/apimachinery/pkg/runtime/serializer"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
multiclusterv1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1"
)
var scheme = runtime.NewScheme()
var codecs = serializer.NewCodecFactory(scheme)
var localSchemeBuilder = runtime.SchemeBuilder{
multiclusterv1alpha1.AddToScheme,
}
// AddToScheme adds all types of this clientset into the given scheme. This allows composition
// of clientsets, like in:
//
// import (
// "k8s.io/client-go/kubernetes"
// clientsetscheme "k8s.io/client-go/kubernetes/scheme"
// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
// )
//
// kclientset, _ := kubernetes.NewForConfig(c)
// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
//
// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
// correctly.
var AddToScheme = localSchemeBuilder.AddToScheme
func init() {
v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"})
utilruntime.Must(AddToScheme(scheme))
}

Просмотреть файл

@ -1,20 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by client-gen. DO NOT EDIT.
// This package contains the scheme of the automatically generated clientset.
package scheme

Просмотреть файл

@ -1,56 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by client-gen. DO NOT EDIT.
package scheme
import (
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
schema "k8s.io/apimachinery/pkg/runtime/schema"
serializer "k8s.io/apimachinery/pkg/runtime/serializer"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
multiclusterv1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1"
)
var Scheme = runtime.NewScheme()
var Codecs = serializer.NewCodecFactory(Scheme)
var ParameterCodec = runtime.NewParameterCodec(Scheme)
var localSchemeBuilder = runtime.SchemeBuilder{
multiclusterv1alpha1.AddToScheme,
}
// AddToScheme adds all types of this clientset into the given scheme. This allows composition
// of clientsets, like in:
//
// import (
// "k8s.io/client-go/kubernetes"
// clientsetscheme "k8s.io/client-go/kubernetes/scheme"
// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
// )
//
// kclientset, _ := kubernetes.NewForConfig(c)
// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
//
// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
// correctly.
var AddToScheme = localSchemeBuilder.AddToScheme
func init() {
v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"})
utilruntime.Must(AddToScheme(Scheme))
}

Просмотреть файл

@ -1,94 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by client-gen. DO NOT EDIT.
package v1alpha1
import (
rest "k8s.io/client-go/rest"
v1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1"
"sigs.k8s.io/work-api/pkg/client/clientset/versioned/scheme"
)
type MulticlusterV1alpha1Interface interface {
RESTClient() rest.Interface
AppliedWorksGetter
WorksGetter
}
// MulticlusterV1alpha1Client is used to interact with features provided by the multicluster.x-k8s.io group.
type MulticlusterV1alpha1Client struct {
restClient rest.Interface
}
func (c *MulticlusterV1alpha1Client) AppliedWorks() AppliedWorkInterface {
return newAppliedWorks(c)
}
func (c *MulticlusterV1alpha1Client) Works(namespace string) WorkInterface {
return newWorks(c, namespace)
}
// NewForConfig creates a new MulticlusterV1alpha1Client for the given config.
func NewForConfig(c *rest.Config) (*MulticlusterV1alpha1Client, error) {
config := *c
if err := setConfigDefaults(&config); err != nil {
return nil, err
}
client, err := rest.RESTClientFor(&config)
if err != nil {
return nil, err
}
return &MulticlusterV1alpha1Client{client}, nil
}
// NewForConfigOrDie creates a new MulticlusterV1alpha1Client for the given config and
// panics if there is an error in the config.
func NewForConfigOrDie(c *rest.Config) *MulticlusterV1alpha1Client {
client, err := NewForConfig(c)
if err != nil {
panic(err)
}
return client
}
// New creates a new MulticlusterV1alpha1Client for the given RESTClient.
func New(c rest.Interface) *MulticlusterV1alpha1Client {
return &MulticlusterV1alpha1Client{c}
}
func setConfigDefaults(config *rest.Config) error {
gv := v1alpha1.SchemeGroupVersion
config.GroupVersion = &gv
config.APIPath = "/apis"
config.NegotiatedSerializer = scheme.Codecs.WithoutConversion()
if config.UserAgent == "" {
config.UserAgent = rest.DefaultKubernetesUserAgent()
}
return nil
}
// RESTClient returns a RESTClient that is used to communicate
// with API server by this client implementation.
func (c *MulticlusterV1alpha1Client) RESTClient() rest.Interface {
if c == nil {
return nil
}
return c.restClient
}

Просмотреть файл

@ -1,184 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by client-gen. DO NOT EDIT.
package v1alpha1
import (
"context"
"time"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch"
rest "k8s.io/client-go/rest"
v1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1"
scheme "sigs.k8s.io/work-api/pkg/client/clientset/versioned/scheme"
)
// AppliedWorksGetter has a method to return a AppliedWorkInterface.
// A group's client should implement this interface.
type AppliedWorksGetter interface {
AppliedWorks() AppliedWorkInterface
}
// AppliedWorkInterface has methods to work with AppliedWork resources.
type AppliedWorkInterface interface {
Create(ctx context.Context, appliedWork *v1alpha1.AppliedWork, opts v1.CreateOptions) (*v1alpha1.AppliedWork, error)
Update(ctx context.Context, appliedWork *v1alpha1.AppliedWork, opts v1.UpdateOptions) (*v1alpha1.AppliedWork, error)
UpdateStatus(ctx context.Context, appliedWork *v1alpha1.AppliedWork, opts v1.UpdateOptions) (*v1alpha1.AppliedWork, error)
Delete(ctx context.Context, name string, opts v1.DeleteOptions) error
DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error
Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.AppliedWork, error)
List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.AppliedWorkList, error)
Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error)
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.AppliedWork, err error)
AppliedWorkExpansion
}
// appliedWorks implements AppliedWorkInterface
type appliedWorks struct {
client rest.Interface
}
// newAppliedWorks returns a AppliedWorks
func newAppliedWorks(c *MulticlusterV1alpha1Client) *appliedWorks {
return &appliedWorks{
client: c.RESTClient(),
}
}
// Get takes name of the appliedWork, and returns the corresponding appliedWork object, and an error if there is any.
func (c *appliedWorks) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.AppliedWork, err error) {
result = &v1alpha1.AppliedWork{}
err = c.client.Get().
Resource("appliedworks").
Name(name).
VersionedParams(&options, scheme.ParameterCodec).
Do(ctx).
Into(result)
return
}
// List takes label and field selectors, and returns the list of AppliedWorks that match those selectors.
func (c *appliedWorks) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.AppliedWorkList, err error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil {
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
result = &v1alpha1.AppliedWorkList{}
err = c.client.Get().
Resource("appliedworks").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Do(ctx).
Into(result)
return
}
// Watch returns a watch.Interface that watches the requested appliedWorks.
func (c *appliedWorks) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil {
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
opts.Watch = true
return c.client.Get().
Resource("appliedworks").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Watch(ctx)
}
// Create takes the representation of a appliedWork and creates it. Returns the server's representation of the appliedWork, and an error, if there is any.
func (c *appliedWorks) Create(ctx context.Context, appliedWork *v1alpha1.AppliedWork, opts v1.CreateOptions) (result *v1alpha1.AppliedWork, err error) {
result = &v1alpha1.AppliedWork{}
err = c.client.Post().
Resource("appliedworks").
VersionedParams(&opts, scheme.ParameterCodec).
Body(appliedWork).
Do(ctx).
Into(result)
return
}
// Update takes the representation of a appliedWork and updates it. Returns the server's representation of the appliedWork, and an error, if there is any.
func (c *appliedWorks) Update(ctx context.Context, appliedWork *v1alpha1.AppliedWork, opts v1.UpdateOptions) (result *v1alpha1.AppliedWork, err error) {
result = &v1alpha1.AppliedWork{}
err = c.client.Put().
Resource("appliedworks").
Name(appliedWork.Name).
VersionedParams(&opts, scheme.ParameterCodec).
Body(appliedWork).
Do(ctx).
Into(result)
return
}
// UpdateStatus was generated because the type contains a Status member.
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
func (c *appliedWorks) UpdateStatus(ctx context.Context, appliedWork *v1alpha1.AppliedWork, opts v1.UpdateOptions) (result *v1alpha1.AppliedWork, err error) {
result = &v1alpha1.AppliedWork{}
err = c.client.Put().
Resource("appliedworks").
Name(appliedWork.Name).
SubResource("status").
VersionedParams(&opts, scheme.ParameterCodec).
Body(appliedWork).
Do(ctx).
Into(result)
return
}
// Delete takes name of the appliedWork and deletes it. Returns an error if one occurs.
func (c *appliedWorks) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
return c.client.Delete().
Resource("appliedworks").
Name(name).
Body(&opts).
Do(ctx).
Error()
}
// DeleteCollection deletes a collection of objects.
func (c *appliedWorks) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
var timeout time.Duration
if listOpts.TimeoutSeconds != nil {
timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second
}
return c.client.Delete().
Resource("appliedworks").
VersionedParams(&listOpts, scheme.ParameterCodec).
Timeout(timeout).
Body(&opts).
Do(ctx).
Error()
}
// Patch applies the patch and returns the patched appliedWork.
func (c *appliedWorks) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.AppliedWork, err error) {
result = &v1alpha1.AppliedWork{}
err = c.client.Patch(pt).
Resource("appliedworks").
Name(name).
SubResource(subresources...).
VersionedParams(&opts, scheme.ParameterCodec).
Body(data).
Do(ctx).
Into(result)
return
}

Просмотреть файл

@ -1,20 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by client-gen. DO NOT EDIT.
// This package has the automatically generated typed clients.
package v1alpha1

Просмотреть файл

@ -1,20 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by client-gen. DO NOT EDIT.
// Package fake has the automatically generated clients.
package fake

Просмотреть файл

@ -1,44 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by client-gen. DO NOT EDIT.
package fake
import (
rest "k8s.io/client-go/rest"
testing "k8s.io/client-go/testing"
v1alpha1 "sigs.k8s.io/work-api/pkg/client/clientset/versioned/typed/apis/v1alpha1"
)
type FakeMulticlusterV1alpha1 struct {
*testing.Fake
}
func (c *FakeMulticlusterV1alpha1) AppliedWorks() v1alpha1.AppliedWorkInterface {
return &FakeAppliedWorks{c}
}
func (c *FakeMulticlusterV1alpha1) Works(namespace string) v1alpha1.WorkInterface {
return &FakeWorks{c, namespace}
}
// RESTClient returns a RESTClient that is used to communicate
// with API server by this client implementation.
func (c *FakeMulticlusterV1alpha1) RESTClient() rest.Interface {
var ret *rest.RESTClient
return ret
}

Просмотреть файл

@ -1,133 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by client-gen. DO NOT EDIT.
package fake
import (
"context"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
labels "k8s.io/apimachinery/pkg/labels"
schema "k8s.io/apimachinery/pkg/runtime/schema"
types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch"
testing "k8s.io/client-go/testing"
v1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1"
)
// FakeAppliedWorks implements AppliedWorkInterface
type FakeAppliedWorks struct {
Fake *FakeMulticlusterV1alpha1
}
var appliedworksResource = schema.GroupVersionResource{Group: "multicluster.x-k8s.io", Version: "v1alpha1", Resource: "appliedworks"}
var appliedworksKind = schema.GroupVersionKind{Group: "multicluster.x-k8s.io", Version: "v1alpha1", Kind: "AppliedWork"}
// Get takes name of the appliedWork, and returns the corresponding appliedWork object, and an error if there is any.
func (c *FakeAppliedWorks) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.AppliedWork, err error) {
obj, err := c.Fake.
Invokes(testing.NewRootGetAction(appliedworksResource, name), &v1alpha1.AppliedWork{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.AppliedWork), err
}
// List takes label and field selectors, and returns the list of AppliedWorks that match those selectors.
func (c *FakeAppliedWorks) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.AppliedWorkList, err error) {
obj, err := c.Fake.
Invokes(testing.NewRootListAction(appliedworksResource, appliedworksKind, opts), &v1alpha1.AppliedWorkList{})
if obj == nil {
return nil, err
}
label, _, _ := testing.ExtractFromListOptions(opts)
if label == nil {
label = labels.Everything()
}
list := &v1alpha1.AppliedWorkList{ListMeta: obj.(*v1alpha1.AppliedWorkList).ListMeta}
for _, item := range obj.(*v1alpha1.AppliedWorkList).Items {
if label.Matches(labels.Set(item.Labels)) {
list.Items = append(list.Items, item)
}
}
return list, err
}
// Watch returns a watch.Interface that watches the requested appliedWorks.
func (c *FakeAppliedWorks) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
return c.Fake.
InvokesWatch(testing.NewRootWatchAction(appliedworksResource, opts))
}
// Create takes the representation of a appliedWork and creates it. Returns the server's representation of the appliedWork, and an error, if there is any.
func (c *FakeAppliedWorks) Create(ctx context.Context, appliedWork *v1alpha1.AppliedWork, opts v1.CreateOptions) (result *v1alpha1.AppliedWork, err error) {
obj, err := c.Fake.
Invokes(testing.NewRootCreateAction(appliedworksResource, appliedWork), &v1alpha1.AppliedWork{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.AppliedWork), err
}
// Update takes the representation of a appliedWork and updates it. Returns the server's representation of the appliedWork, and an error, if there is any.
func (c *FakeAppliedWorks) Update(ctx context.Context, appliedWork *v1alpha1.AppliedWork, opts v1.UpdateOptions) (result *v1alpha1.AppliedWork, err error) {
obj, err := c.Fake.
Invokes(testing.NewRootUpdateAction(appliedworksResource, appliedWork), &v1alpha1.AppliedWork{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.AppliedWork), err
}
// UpdateStatus was generated because the type contains a Status member.
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
func (c *FakeAppliedWorks) UpdateStatus(ctx context.Context, appliedWork *v1alpha1.AppliedWork, opts v1.UpdateOptions) (*v1alpha1.AppliedWork, error) {
obj, err := c.Fake.
Invokes(testing.NewRootUpdateSubresourceAction(appliedworksResource, "status", appliedWork), &v1alpha1.AppliedWork{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.AppliedWork), err
}
// Delete takes name of the appliedWork and deletes it. Returns an error if one occurs.
func (c *FakeAppliedWorks) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
_, err := c.Fake.
Invokes(testing.NewRootDeleteAction(appliedworksResource, name), &v1alpha1.AppliedWork{})
return err
}
// DeleteCollection deletes a collection of objects.
func (c *FakeAppliedWorks) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
action := testing.NewRootDeleteCollectionAction(appliedworksResource, listOpts)
_, err := c.Fake.Invokes(action, &v1alpha1.AppliedWorkList{})
return err
}
// Patch applies the patch and returns the patched appliedWork.
func (c *FakeAppliedWorks) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.AppliedWork, err error) {
obj, err := c.Fake.
Invokes(testing.NewRootPatchSubresourceAction(appliedworksResource, name, pt, data, subresources...), &v1alpha1.AppliedWork{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.AppliedWork), err
}

Просмотреть файл

@ -1,142 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by client-gen. DO NOT EDIT.
package fake
import (
"context"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
labels "k8s.io/apimachinery/pkg/labels"
schema "k8s.io/apimachinery/pkg/runtime/schema"
types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch"
testing "k8s.io/client-go/testing"
v1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1"
)
// FakeWorks implements WorkInterface
type FakeWorks struct {
Fake *FakeMulticlusterV1alpha1
ns string
}
var worksResource = schema.GroupVersionResource{Group: "multicluster.x-k8s.io", Version: "v1alpha1", Resource: "works"}
var worksKind = schema.GroupVersionKind{Group: "multicluster.x-k8s.io", Version: "v1alpha1", Kind: "Work"}
// Get takes name of the work, and returns the corresponding work object, and an error if there is any.
func (c *FakeWorks) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.Work, err error) {
obj, err := c.Fake.
Invokes(testing.NewGetAction(worksResource, c.ns, name), &v1alpha1.Work{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.Work), err
}
// List takes label and field selectors, and returns the list of Works that match those selectors.
func (c *FakeWorks) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.WorkList, err error) {
obj, err := c.Fake.
Invokes(testing.NewListAction(worksResource, worksKind, c.ns, opts), &v1alpha1.WorkList{})
if obj == nil {
return nil, err
}
label, _, _ := testing.ExtractFromListOptions(opts)
if label == nil {
label = labels.Everything()
}
list := &v1alpha1.WorkList{ListMeta: obj.(*v1alpha1.WorkList).ListMeta}
for _, item := range obj.(*v1alpha1.WorkList).Items {
if label.Matches(labels.Set(item.Labels)) {
list.Items = append(list.Items, item)
}
}
return list, err
}
// Watch returns a watch.Interface that watches the requested works.
func (c *FakeWorks) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
return c.Fake.
InvokesWatch(testing.NewWatchAction(worksResource, c.ns, opts))
}
// Create takes the representation of a work and creates it. Returns the server's representation of the work, and an error, if there is any.
func (c *FakeWorks) Create(ctx context.Context, work *v1alpha1.Work, opts v1.CreateOptions) (result *v1alpha1.Work, err error) {
obj, err := c.Fake.
Invokes(testing.NewCreateAction(worksResource, c.ns, work), &v1alpha1.Work{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.Work), err
}
// Update takes the representation of a work and updates it. Returns the server's representation of the work, and an error, if there is any.
func (c *FakeWorks) Update(ctx context.Context, work *v1alpha1.Work, opts v1.UpdateOptions) (result *v1alpha1.Work, err error) {
obj, err := c.Fake.
Invokes(testing.NewUpdateAction(worksResource, c.ns, work), &v1alpha1.Work{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.Work), err
}
// UpdateStatus was generated because the type contains a Status member.
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
func (c *FakeWorks) UpdateStatus(ctx context.Context, work *v1alpha1.Work, opts v1.UpdateOptions) (*v1alpha1.Work, error) {
obj, err := c.Fake.
Invokes(testing.NewUpdateSubresourceAction(worksResource, "status", c.ns, work), &v1alpha1.Work{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.Work), err
}
// Delete takes name of the work and deletes it. Returns an error if one occurs.
func (c *FakeWorks) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
_, err := c.Fake.
Invokes(testing.NewDeleteAction(worksResource, c.ns, name), &v1alpha1.Work{})
return err
}
// DeleteCollection deletes a collection of objects.
func (c *FakeWorks) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
action := testing.NewDeleteCollectionAction(worksResource, c.ns, listOpts)
_, err := c.Fake.Invokes(action, &v1alpha1.WorkList{})
return err
}
// Patch applies the patch and returns the patched work.
func (c *FakeWorks) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.Work, err error) {
obj, err := c.Fake.
Invokes(testing.NewPatchSubresourceAction(worksResource, c.ns, name, pt, data, subresources...), &v1alpha1.Work{})
if obj == nil {
return nil, err
}
return obj.(*v1alpha1.Work), err
}

Просмотреть файл

@ -1,23 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by client-gen. DO NOT EDIT.
package v1alpha1
type AppliedWorkExpansion interface{}
type WorkExpansion interface{}

Просмотреть файл

@ -1,195 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by client-gen. DO NOT EDIT.
package v1alpha1
import (
"context"
"time"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
types "k8s.io/apimachinery/pkg/types"
watch "k8s.io/apimachinery/pkg/watch"
rest "k8s.io/client-go/rest"
v1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1"
scheme "sigs.k8s.io/work-api/pkg/client/clientset/versioned/scheme"
)
// WorksGetter has a method to return a WorkInterface.
// A group's client should implement this interface.
type WorksGetter interface {
Works(namespace string) WorkInterface
}
// WorkInterface has methods to work with Work resources.
type WorkInterface interface {
Create(ctx context.Context, work *v1alpha1.Work, opts v1.CreateOptions) (*v1alpha1.Work, error)
Update(ctx context.Context, work *v1alpha1.Work, opts v1.UpdateOptions) (*v1alpha1.Work, error)
UpdateStatus(ctx context.Context, work *v1alpha1.Work, opts v1.UpdateOptions) (*v1alpha1.Work, error)
Delete(ctx context.Context, name string, opts v1.DeleteOptions) error
DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error
Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.Work, error)
List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.WorkList, error)
Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error)
Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.Work, err error)
WorkExpansion
}
// works implements WorkInterface
type works struct {
client rest.Interface
ns string
}
// newWorks returns a Works
func newWorks(c *MulticlusterV1alpha1Client, namespace string) *works {
return &works{
client: c.RESTClient(),
ns: namespace,
}
}
// Get takes name of the work, and returns the corresponding work object, and an error if there is any.
func (c *works) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.Work, err error) {
result = &v1alpha1.Work{}
err = c.client.Get().
Namespace(c.ns).
Resource("works").
Name(name).
VersionedParams(&options, scheme.ParameterCodec).
Do(ctx).
Into(result)
return
}
// List takes label and field selectors, and returns the list of Works that match those selectors.
func (c *works) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.WorkList, err error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil {
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
result = &v1alpha1.WorkList{}
err = c.client.Get().
Namespace(c.ns).
Resource("works").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Do(ctx).
Into(result)
return
}
// Watch returns a watch.Interface that watches the requested works.
func (c *works) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {
var timeout time.Duration
if opts.TimeoutSeconds != nil {
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
}
opts.Watch = true
return c.client.Get().
Namespace(c.ns).
Resource("works").
VersionedParams(&opts, scheme.ParameterCodec).
Timeout(timeout).
Watch(ctx)
}
// Create takes the representation of a work and creates it. Returns the server's representation of the work, and an error, if there is any.
func (c *works) Create(ctx context.Context, work *v1alpha1.Work, opts v1.CreateOptions) (result *v1alpha1.Work, err error) {
result = &v1alpha1.Work{}
err = c.client.Post().
Namespace(c.ns).
Resource("works").
VersionedParams(&opts, scheme.ParameterCodec).
Body(work).
Do(ctx).
Into(result)
return
}
// Update takes the representation of a work and updates it. Returns the server's representation of the work, and an error, if there is any.
func (c *works) Update(ctx context.Context, work *v1alpha1.Work, opts v1.UpdateOptions) (result *v1alpha1.Work, err error) {
result = &v1alpha1.Work{}
err = c.client.Put().
Namespace(c.ns).
Resource("works").
Name(work.Name).
VersionedParams(&opts, scheme.ParameterCodec).
Body(work).
Do(ctx).
Into(result)
return
}
// UpdateStatus was generated because the type contains a Status member.
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
func (c *works) UpdateStatus(ctx context.Context, work *v1alpha1.Work, opts v1.UpdateOptions) (result *v1alpha1.Work, err error) {
result = &v1alpha1.Work{}
err = c.client.Put().
Namespace(c.ns).
Resource("works").
Name(work.Name).
SubResource("status").
VersionedParams(&opts, scheme.ParameterCodec).
Body(work).
Do(ctx).
Into(result)
return
}
// Delete takes name of the work and deletes it. Returns an error if one occurs.
func (c *works) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {
return c.client.Delete().
Namespace(c.ns).
Resource("works").
Name(name).
Body(&opts).
Do(ctx).
Error()
}
// DeleteCollection deletes a collection of objects.
func (c *works) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {
var timeout time.Duration
if listOpts.TimeoutSeconds != nil {
timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second
}
return c.client.Delete().
Namespace(c.ns).
Resource("works").
VersionedParams(&listOpts, scheme.ParameterCodec).
Timeout(timeout).
Body(&opts).
Do(ctx).
Error()
}
// Patch applies the patch and returns the patched work.
func (c *works) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.Work, err error) {
result = &v1alpha1.Work{}
err = c.client.Patch(pt).
Namespace(c.ns).
Resource("works").
Name(name).
SubResource(subresources...).
VersionedParams(&opts, scheme.ParameterCodec).
Body(data).
Do(ctx).
Into(result)
return
}

Просмотреть файл

@ -1,46 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by informer-gen. DO NOT EDIT.
package apis
import (
v1alpha1 "sigs.k8s.io/work-api/pkg/client/informers/externalversions/apis/v1alpha1"
internalinterfaces "sigs.k8s.io/work-api/pkg/client/informers/externalversions/internalinterfaces"
)
// Interface provides access to each of this group's versions.
type Interface interface {
// V1alpha1 provides access to shared informers for resources in V1alpha1.
V1alpha1() v1alpha1.Interface
}
type group struct {
factory internalinterfaces.SharedInformerFactory
namespace string
tweakListOptions internalinterfaces.TweakListOptionsFunc
}
// New returns a new Interface.
func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface {
return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions}
}
// V1alpha1 returns a new v1alpha1.Interface.
func (g *group) V1alpha1() v1alpha1.Interface {
return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions)
}

Просмотреть файл

@ -1,89 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by informer-gen. DO NOT EDIT.
package v1alpha1
import (
"context"
time "time"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
watch "k8s.io/apimachinery/pkg/watch"
cache "k8s.io/client-go/tools/cache"
apisv1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1"
versioned "sigs.k8s.io/work-api/pkg/client/clientset/versioned"
internalinterfaces "sigs.k8s.io/work-api/pkg/client/informers/externalversions/internalinterfaces"
v1alpha1 "sigs.k8s.io/work-api/pkg/client/listers/apis/v1alpha1"
)
// AppliedWorkInformer provides access to a shared informer and lister for
// AppliedWorks.
type AppliedWorkInformer interface {
Informer() cache.SharedIndexInformer
Lister() v1alpha1.AppliedWorkLister
}
type appliedWorkInformer struct {
factory internalinterfaces.SharedInformerFactory
tweakListOptions internalinterfaces.TweakListOptionsFunc
}
// NewAppliedWorkInformer constructs a new informer for AppliedWork type.
// Always prefer using an informer factory to get a shared informer instead of getting an independent
// one. This reduces memory footprint and number of connections to the server.
func NewAppliedWorkInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return NewFilteredAppliedWorkInformer(client, resyncPeriod, indexers, nil)
}
// NewFilteredAppliedWorkInformer constructs a new informer for AppliedWork type.
// Always prefer using an informer factory to get a shared informer instead of getting an independent
// one. This reduces memory footprint and number of connections to the server.
func NewFilteredAppliedWorkInformer(client versioned.Interface, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer {
return cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.MulticlusterV1alpha1().AppliedWorks().List(context.TODO(), options)
},
WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.MulticlusterV1alpha1().AppliedWorks().Watch(context.TODO(), options)
},
},
&apisv1alpha1.AppliedWork{},
resyncPeriod,
indexers,
)
}
func (f *appliedWorkInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
return NewFilteredAppliedWorkInformer(client, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions)
}
func (f *appliedWorkInformer) Informer() cache.SharedIndexInformer {
return f.factory.InformerFor(&apisv1alpha1.AppliedWork{}, f.defaultInformer)
}
func (f *appliedWorkInformer) Lister() v1alpha1.AppliedWorkLister {
return v1alpha1.NewAppliedWorkLister(f.Informer().GetIndexer())
}

Просмотреть файл

@ -1,52 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by informer-gen. DO NOT EDIT.
package v1alpha1
import (
internalinterfaces "sigs.k8s.io/work-api/pkg/client/informers/externalversions/internalinterfaces"
)
// Interface provides access to all the informers in this group version.
type Interface interface {
// AppliedWorks returns a AppliedWorkInformer.
AppliedWorks() AppliedWorkInformer
// Works returns a WorkInformer.
Works() WorkInformer
}
type version struct {
factory internalinterfaces.SharedInformerFactory
namespace string
tweakListOptions internalinterfaces.TweakListOptionsFunc
}
// New returns a new Interface.
func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface {
return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions}
}
// AppliedWorks returns a AppliedWorkInformer.
func (v *version) AppliedWorks() AppliedWorkInformer {
return &appliedWorkInformer{factory: v.factory, tweakListOptions: v.tweakListOptions}
}
// Works returns a WorkInformer.
func (v *version) Works() WorkInformer {
return &workInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions}
}

Просмотреть файл

@ -1,90 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by informer-gen. DO NOT EDIT.
package v1alpha1
import (
"context"
time "time"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
watch "k8s.io/apimachinery/pkg/watch"
cache "k8s.io/client-go/tools/cache"
apisv1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1"
versioned "sigs.k8s.io/work-api/pkg/client/clientset/versioned"
internalinterfaces "sigs.k8s.io/work-api/pkg/client/informers/externalversions/internalinterfaces"
v1alpha1 "sigs.k8s.io/work-api/pkg/client/listers/apis/v1alpha1"
)
// WorkInformer provides access to a shared informer and lister for
// Works.
type WorkInformer interface {
Informer() cache.SharedIndexInformer
Lister() v1alpha1.WorkLister
}
type workInformer struct {
factory internalinterfaces.SharedInformerFactory
tweakListOptions internalinterfaces.TweakListOptionsFunc
namespace string
}
// NewWorkInformer constructs a new informer for Work type.
// Always prefer using an informer factory to get a shared informer instead of getting an independent
// one. This reduces memory footprint and number of connections to the server.
func NewWorkInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer {
return NewFilteredWorkInformer(client, namespace, resyncPeriod, indexers, nil)
}
// NewFilteredWorkInformer constructs a new informer for Work type.
// Always prefer using an informer factory to get a shared informer instead of getting an independent
// one. This reduces memory footprint and number of connections to the server.
func NewFilteredWorkInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer {
return cache.NewSharedIndexInformer(
&cache.ListWatch{
ListFunc: func(options v1.ListOptions) (runtime.Object, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.MulticlusterV1alpha1().Works(namespace).List(context.TODO(), options)
},
WatchFunc: func(options v1.ListOptions) (watch.Interface, error) {
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.MulticlusterV1alpha1().Works(namespace).Watch(context.TODO(), options)
},
},
&apisv1alpha1.Work{},
resyncPeriod,
indexers,
)
}
func (f *workInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer {
return NewFilteredWorkInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions)
}
func (f *workInformer) Informer() cache.SharedIndexInformer {
return f.factory.InformerFor(&apisv1alpha1.Work{}, f.defaultInformer)
}
func (f *workInformer) Lister() v1alpha1.WorkLister {
return v1alpha1.NewWorkLister(f.Informer().GetIndexer())
}

Просмотреть файл

@ -1,180 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by informer-gen. DO NOT EDIT.
package externalversions
import (
reflect "reflect"
sync "sync"
time "time"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
schema "k8s.io/apimachinery/pkg/runtime/schema"
cache "k8s.io/client-go/tools/cache"
versioned "sigs.k8s.io/work-api/pkg/client/clientset/versioned"
apis "sigs.k8s.io/work-api/pkg/client/informers/externalversions/apis"
internalinterfaces "sigs.k8s.io/work-api/pkg/client/informers/externalversions/internalinterfaces"
)
// SharedInformerOption defines the functional option type for SharedInformerFactory.
type SharedInformerOption func(*sharedInformerFactory) *sharedInformerFactory
type sharedInformerFactory struct {
client versioned.Interface
namespace string
tweakListOptions internalinterfaces.TweakListOptionsFunc
lock sync.Mutex
defaultResync time.Duration
customResync map[reflect.Type]time.Duration
informers map[reflect.Type]cache.SharedIndexInformer
// startedInformers is used for tracking which informers have been started.
// This allows Start() to be called multiple times safely.
startedInformers map[reflect.Type]bool
}
// WithCustomResyncConfig sets a custom resync period for the specified informer types.
func WithCustomResyncConfig(resyncConfig map[v1.Object]time.Duration) SharedInformerOption {
return func(factory *sharedInformerFactory) *sharedInformerFactory {
for k, v := range resyncConfig {
factory.customResync[reflect.TypeOf(k)] = v
}
return factory
}
}
// WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory.
func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerOption {
return func(factory *sharedInformerFactory) *sharedInformerFactory {
factory.tweakListOptions = tweakListOptions
return factory
}
}
// WithNamespace limits the SharedInformerFactory to the specified namespace.
func WithNamespace(namespace string) SharedInformerOption {
return func(factory *sharedInformerFactory) *sharedInformerFactory {
factory.namespace = namespace
return factory
}
}
// NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces.
func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory {
return NewSharedInformerFactoryWithOptions(client, defaultResync)
}
// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory.
// Listers obtained via this SharedInformerFactory will be subject to the same filters
// as specified here.
// Deprecated: Please use NewSharedInformerFactoryWithOptions instead
func NewFilteredSharedInformerFactory(client versioned.Interface, defaultResync time.Duration, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory {
return NewSharedInformerFactoryWithOptions(client, defaultResync, WithNamespace(namespace), WithTweakListOptions(tweakListOptions))
}
// NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options.
func NewSharedInformerFactoryWithOptions(client versioned.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory {
factory := &sharedInformerFactory{
client: client,
namespace: v1.NamespaceAll,
defaultResync: defaultResync,
informers: make(map[reflect.Type]cache.SharedIndexInformer),
startedInformers: make(map[reflect.Type]bool),
customResync: make(map[reflect.Type]time.Duration),
}
// Apply all options
for _, opt := range options {
factory = opt(factory)
}
return factory
}
// Start initializes all requested informers.
func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) {
f.lock.Lock()
defer f.lock.Unlock()
for informerType, informer := range f.informers {
if !f.startedInformers[informerType] {
go informer.Run(stopCh)
f.startedInformers[informerType] = true
}
}
}
// WaitForCacheSync waits for all started informers' cache were synced.
func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool {
informers := func() map[reflect.Type]cache.SharedIndexInformer {
f.lock.Lock()
defer f.lock.Unlock()
informers := map[reflect.Type]cache.SharedIndexInformer{}
for informerType, informer := range f.informers {
if f.startedInformers[informerType] {
informers[informerType] = informer
}
}
return informers
}()
res := map[reflect.Type]bool{}
for informType, informer := range informers {
res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced)
}
return res
}
// InternalInformerFor returns the SharedIndexInformer for obj using an internal
// client.
func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer {
f.lock.Lock()
defer f.lock.Unlock()
informerType := reflect.TypeOf(obj)
informer, exists := f.informers[informerType]
if exists {
return informer
}
resyncPeriod, exists := f.customResync[informerType]
if !exists {
resyncPeriod = f.defaultResync
}
informer = newFunc(f.client, resyncPeriod)
f.informers[informerType] = informer
return informer
}
// SharedInformerFactory provides shared informers for resources in all known
// API group versions.
type SharedInformerFactory interface {
internalinterfaces.SharedInformerFactory
ForResource(resource schema.GroupVersionResource) (GenericInformer, error)
WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool
Multicluster() apis.Interface
}
func (f *sharedInformerFactory) Multicluster() apis.Interface {
return apis.New(f, f.namespace, f.tweakListOptions)
}

Просмотреть файл

@ -1,64 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by informer-gen. DO NOT EDIT.
package externalversions
import (
"fmt"
schema "k8s.io/apimachinery/pkg/runtime/schema"
cache "k8s.io/client-go/tools/cache"
v1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1"
)
// GenericInformer is type of SharedIndexInformer which will locate and delegate to other
// sharedInformers based on type
type GenericInformer interface {
Informer() cache.SharedIndexInformer
Lister() cache.GenericLister
}
type genericInformer struct {
informer cache.SharedIndexInformer
resource schema.GroupResource
}
// Informer returns the SharedIndexInformer.
func (f *genericInformer) Informer() cache.SharedIndexInformer {
return f.informer
}
// Lister returns the GenericLister.
func (f *genericInformer) Lister() cache.GenericLister {
return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource)
}
// ForResource gives generic access to a shared informer of the matching type
// TODO extend this to unknown resources with a client pool
func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) {
switch resource {
// Group=multicluster.x-k8s.io, Version=v1alpha1
case v1alpha1.SchemeGroupVersion.WithResource("appliedworks"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Multicluster().V1alpha1().AppliedWorks().Informer()}, nil
case v1alpha1.SchemeGroupVersion.WithResource("works"):
return &genericInformer{resource: resource.GroupResource(), informer: f.Multicluster().V1alpha1().Works().Informer()}, nil
}
return nil, fmt.Errorf("no informer found for %v", resource)
}

Просмотреть файл

@ -1,40 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by informer-gen. DO NOT EDIT.
package internalinterfaces
import (
time "time"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
cache "k8s.io/client-go/tools/cache"
versioned "sigs.k8s.io/work-api/pkg/client/clientset/versioned"
)
// NewInformerFunc takes versioned.Interface and time.Duration to return a SharedIndexInformer.
type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer
// SharedInformerFactory a small interface to allow for adding an informer without an import cycle
type SharedInformerFactory interface {
Start(stopCh <-chan struct{})
InformerFor(obj runtime.Object, newFunc NewInformerFunc) cache.SharedIndexInformer
}
// TweakListOptionsFunc is a function that transforms a v1.ListOptions.
type TweakListOptionsFunc func(*v1.ListOptions)

Просмотреть файл

@ -1,68 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by lister-gen. DO NOT EDIT.
package v1alpha1
import (
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
v1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1"
)
// AppliedWorkLister helps list AppliedWorks.
// All objects returned here must be treated as read-only.
type AppliedWorkLister interface {
// List lists all AppliedWorks in the indexer.
// Objects returned here must be treated as read-only.
List(selector labels.Selector) (ret []*v1alpha1.AppliedWork, err error)
// Get retrieves the AppliedWork from the index for a given name.
// Objects returned here must be treated as read-only.
Get(name string) (*v1alpha1.AppliedWork, error)
AppliedWorkListerExpansion
}
// appliedWorkLister implements the AppliedWorkLister interface.
type appliedWorkLister struct {
indexer cache.Indexer
}
// NewAppliedWorkLister returns a new AppliedWorkLister.
func NewAppliedWorkLister(indexer cache.Indexer) AppliedWorkLister {
return &appliedWorkLister{indexer: indexer}
}
// List lists all AppliedWorks in the indexer.
func (s *appliedWorkLister) List(selector labels.Selector) (ret []*v1alpha1.AppliedWork, err error) {
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
ret = append(ret, m.(*v1alpha1.AppliedWork))
})
return ret, err
}
// Get retrieves the AppliedWork from the index for a given name.
func (s *appliedWorkLister) Get(name string) (*v1alpha1.AppliedWork, error) {
obj, exists, err := s.indexer.GetByKey(name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(v1alpha1.Resource("appliedwork"), name)
}
return obj.(*v1alpha1.AppliedWork), nil
}

Просмотреть файл

@ -1,31 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by lister-gen. DO NOT EDIT.
package v1alpha1
// AppliedWorkListerExpansion allows custom methods to be added to
// AppliedWorkLister.
type AppliedWorkListerExpansion interface{}
// WorkListerExpansion allows custom methods to be added to
// WorkLister.
type WorkListerExpansion interface{}
// WorkNamespaceListerExpansion allows custom methods to be added to
// WorkNamespaceLister.
type WorkNamespaceListerExpansion interface{}

Просмотреть файл

@ -1,99 +0,0 @@
/*
Copyright 2021 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.
*/
// Code generated by lister-gen. DO NOT EDIT.
package v1alpha1
import (
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/client-go/tools/cache"
v1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1"
)
// WorkLister helps list Works.
// All objects returned here must be treated as read-only.
type WorkLister interface {
// List lists all Works in the indexer.
// Objects returned here must be treated as read-only.
List(selector labels.Selector) (ret []*v1alpha1.Work, err error)
// Works returns an object that can list and get Works.
Works(namespace string) WorkNamespaceLister
WorkListerExpansion
}
// workLister implements the WorkLister interface.
type workLister struct {
indexer cache.Indexer
}
// NewWorkLister returns a new WorkLister.
func NewWorkLister(indexer cache.Indexer) WorkLister {
return &workLister{indexer: indexer}
}
// List lists all Works in the indexer.
func (s *workLister) List(selector labels.Selector) (ret []*v1alpha1.Work, err error) {
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
ret = append(ret, m.(*v1alpha1.Work))
})
return ret, err
}
// Works returns an object that can list and get Works.
func (s *workLister) Works(namespace string) WorkNamespaceLister {
return workNamespaceLister{indexer: s.indexer, namespace: namespace}
}
// WorkNamespaceLister helps list and get Works.
// All objects returned here must be treated as read-only.
type WorkNamespaceLister interface {
// List lists all Works in the indexer for a given namespace.
// Objects returned here must be treated as read-only.
List(selector labels.Selector) (ret []*v1alpha1.Work, err error)
// Get retrieves the Work from the indexer for a given namespace and name.
// Objects returned here must be treated as read-only.
Get(name string) (*v1alpha1.Work, error)
WorkNamespaceListerExpansion
}
// workNamespaceLister implements the WorkNamespaceLister
// interface.
type workNamespaceLister struct {
indexer cache.Indexer
namespace string
}
// List lists all Works in the indexer for a given namespace.
func (s workNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.Work, err error) {
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
ret = append(ret, m.(*v1alpha1.Work))
})
return ret, err
}
// Get retrieves the Work from the indexer for a given namespace and name.
func (s workNamespaceLister) Get(name string) (*v1alpha1.Work, error) {
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(v1alpha1.Resource("work"), name)
}
return obj.(*v1alpha1.Work), nil
}

Просмотреть файл

@ -1,222 +0,0 @@
/*
Copyright 2021 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 controllers
import (
"context"
"sigs.k8s.io/work-api/pkg/utils"
"time"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
utilrand "k8s.io/apimachinery/pkg/util/rand"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
workv1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1"
)
var _ = Describe("work reconciler", func() {
const (
timeout = time.Second * 30
interval = time.Second * 1
)
var (
resourceName string
resourceNamespace string
workName string
workNamespace string
configMapA corev1.ConfigMap
work workv1alpha1.Work
)
BeforeEach(func() {
workName = utilrand.String(5)
workNamespace = utilrand.String(5)
resourceName = utilrand.String(5)
resourceNamespace = utilrand.String(5)
wns := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: workNamespace,
},
}
By("Create a namespace for Work objects")
_, err := k8sClient.CoreV1().Namespaces().Create(context.Background(), wns, metav1.CreateOptions{})
Expect(err).Should(SatisfyAny(Succeed(), &utils.AlreadyExistMatcher{}))
rns := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: resourceNamespace,
},
}
By("Create a namespace for Manifest Resources")
_, err = k8sClient.CoreV1().Namespaces().Create(context.Background(), rns, metav1.CreateOptions{})
Expect(err).Should(SatisfyAny(Succeed(), &utils.AlreadyExistMatcher{}))
configMapA = corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "ConfigMap",
},
ObjectMeta: metav1.ObjectMeta{
Name: resourceName,
Namespace: resourceNamespace,
},
Data: map[string]string{
"test": "test",
},
}
work = workv1alpha1.Work{
ObjectMeta: metav1.ObjectMeta{
Name: workName,
Namespace: workNamespace,
},
Spec: workv1alpha1.WorkSpec{
Workload: workv1alpha1.WorkloadTemplate{
Manifests: []workv1alpha1.Manifest{
{
RawExtension: runtime.RawExtension{Object: &configMapA},
},
},
},
},
}
})
AfterEach(func() {
Expect(workClient.MulticlusterV1alpha1().Works(workNamespace).Delete(context.Background(), workName, metav1.DeleteOptions{})).Should(Succeed())
})
Context("Work Creation Process", func() {
It("create a new work object in the hub cluster", func() {
_, err := workClient.MulticlusterV1alpha1().Works(workNamespace).Create(context.Background(), &work, metav1.CreateOptions{})
Expect(err).ShouldNot(HaveOccurred())
By("work object should eventually contain a finalizer.")
Eventually(func() bool {
createdWork, err := workClient.MulticlusterV1alpha1().Works(workNamespace).Get(context.Background(), workName, metav1.GetOptions{})
if err != nil {
return false
}
return controllerutil.ContainsFinalizer(createdWork, workFinalizer)
}, timeout, interval).Should(BeTrue())
By("corresponding appliedWork Resource should have been created.")
Eventually(func() bool {
appliedWorkObject, err := workClient.MulticlusterV1alpha1().AppliedWorks().Get(context.Background(), workName, metav1.GetOptions{})
if err != nil {
return false
}
return appliedWorkObject.Spec.WorkName == workName
}, timeout, interval).Should(BeTrue())
By("manifests should have been applied.")
Eventually(func() bool {
resource, err := k8sClient.CoreV1().ConfigMaps(resourceNamespace).Get(context.Background(), resourceName, metav1.GetOptions{})
if err != nil {
return false
}
return resource.GetName() == resourceName
}, timeout, interval).Should(BeTrue())
By("status should have been saved for each manifests applied.")
Eventually(func() bool {
currentWork, err := workClient.MulticlusterV1alpha1().Works(workNamespace).Get(context.Background(), workName, metav1.GetOptions{})
if err == nil {
if len(currentWork.Status.ManifestConditions) > 0 {
return currentWork.Status.ManifestConditions[0].Identifier.Name == resourceName &&
currentWork.Status.ManifestConditions[0].Identifier.Namespace == resourceNamespace &&
currentWork.Status.Conditions[0].Status == metav1.ConditionTrue
}
}
return false
}, timeout, interval).Should(BeTrue())
By("AppliedResourceMeta details should have been created on AppliedWork's status")
Eventually(func() bool {
appliedWorkObject, err := workClient.MulticlusterV1alpha1().AppliedWorks().Get(context.Background(), workName, metav1.GetOptions{})
if err != nil {
return false
}
return appliedWorkObject.Status.AppliedResources[0].Name == resourceName &&
appliedWorkObject.Status.AppliedResources[0].Namespace == resourceNamespace
}, timeout, interval).Should(BeTrue())
})
Context("Work is being updated", func() {
It("modify a manifest, then update the work object", func() {
By("creating a new work object")
createdWork, err := workClient.MulticlusterV1alpha1().Works(workNamespace).Create(context.Background(), &work, metav1.CreateOptions{})
Expect(err).ShouldNot(HaveOccurred())
cm := corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "ConfigMap",
},
ObjectMeta: metav1.ObjectMeta{
Name: resourceName,
Namespace: resourceNamespace,
},
Data: map[string]string{
"updated_test": "updated_test",
},
}
createdWork.Spec.Workload.Manifests = []workv1alpha1.Manifest{
{
RawExtension: runtime.RawExtension{Object: &cm},
},
}
By("Updating the work object")
_, err = workClient.MulticlusterV1alpha1().Works(workNamespace).Update(context.Background(), createdWork, metav1.UpdateOptions{})
Expect(err).ShouldNot(HaveOccurred())
By("Work status should be updated")
Eventually(func() bool {
currentWork, err := workClient.MulticlusterV1alpha1().Works(workNamespace).Get(context.Background(), workName, metav1.GetOptions{})
if err == nil {
if len(currentWork.Status.Conditions) > 0 && len(currentWork.Status.ManifestConditions) > 0 {
return currentWork.Status.ManifestConditions[0].Identifier.Name == cm.Name &&
currentWork.Status.ManifestConditions[0].Identifier.Namespace == cm.Namespace &&
currentWork.Status.Conditions[0].Type == ConditionTypeApplied &&
currentWork.Status.Conditions[0].Status == metav1.ConditionTrue
}
}
return false
}, timeout, interval).Should(BeTrue())
By("the manifest resource should be created")
Eventually(func() bool {
configMap, err := k8sClient.CoreV1().ConfigMaps(resourceNamespace).Get(context.Background(), resourceName, metav1.GetOptions{})
if err == nil {
return configMap.Data["updated_test"] == "updated_test"
}
return false
}, timeout, interval).Should(BeTrue())
})
})
})
})

Просмотреть файл

@ -19,6 +19,7 @@ package controllers
import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/types"
"time"
. "github.com/onsi/ginkgo"
@ -74,7 +75,7 @@ var _ = Describe("Work Controller", func() {
work := &workv1alpha1.Work{
ObjectMeta: metav1.ObjectMeta{
Name: "comfigmap-work",
Name: "test-work",
Namespace: workNamespace,
},
Spec: workv1alpha1.WorkSpec{
@ -88,7 +89,7 @@ var _ = Describe("Work Controller", func() {
},
}
_, err := workClient.MulticlusterV1alpha1().Works(workNamespace).Create(context.Background(), work, metav1.CreateOptions{})
err := workClient.Create(context.Background(), work)
Expect(err).ToNot(HaveOccurred())
Eventually(func() error {
@ -97,7 +98,8 @@ var _ = Describe("Work Controller", func() {
}, timeout, interval).Should(Succeed())
Eventually(func() error {
resultWork, err := workClient.MulticlusterV1alpha1().Works(workNamespace).Get(context.Background(), work.Name, metav1.GetOptions{})
resultWork := workv1alpha1.Work{}
err := workClient.Get(context.Background(), types.NamespacedName{Name: work.GetName(), Namespace: workNamespace}, &resultWork)
if err != nil {
return err
}

Просмотреть файл

@ -32,7 +32,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/predicate"
workv1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1"
"sigs.k8s.io/work-api/pkg/client/clientset/versioned"
)
const (
@ -45,7 +44,7 @@ const (
// FinalizeWorkReconciler reconciles a Work object for finalization
type FinalizeWorkReconciler struct {
client client.Client
spokeClient versioned.Interface
spokeClient client.Client
recorder record.EventRecorder
}
@ -69,7 +68,7 @@ func (r *FinalizeWorkReconciler) Reconcile(ctx context.Context, req ctrl.Request
var appliedWork *workv1alpha1.AppliedWork
if controllerutil.ContainsFinalizer(work, workFinalizer) {
_, err = r.spokeClient.MulticlusterV1alpha1().AppliedWorks().Get(ctx, req.Name, metav1.GetOptions{})
err = r.spokeClient.Get(ctx, req.NamespacedName, appliedWork)
if err != nil {
if errors.IsNotFound(err) {
klog.ErrorS(err, "the finalizer appliedWork object doesn't exist, we will add it back", "name", req.Name)
@ -93,7 +92,7 @@ func (r *FinalizeWorkReconciler) Reconcile(ctx context.Context, req ctrl.Request
WorkNamespace: req.Namespace,
},
}
_, err = r.spokeClient.MulticlusterV1alpha1().AppliedWorks().Create(ctx, appliedWork, metav1.CreateOptions{})
err = r.spokeClient.Create(ctx, appliedWork)
if err != nil && !errors.IsAlreadyExists(err) {
// if this conflicts, we'll simply try again later
klog.ErrorS(err, "failed to create the appliedWork", "name", req.Name)
@ -114,8 +113,14 @@ func (r *FinalizeWorkReconciler) Reconcile(ctx context.Context, req ctrl.Request
func (r *FinalizeWorkReconciler) garbageCollectAppliedWork(ctx context.Context, work *workv1alpha1.Work) (ctrl.Result, error) {
if controllerutil.ContainsFinalizer(work, workFinalizer) {
deletePolicy := metav1.DeletePropagationForeground
err := r.spokeClient.MulticlusterV1alpha1().AppliedWorks().Delete(ctx, work.Name,
metav1.DeleteOptions{PropagationPolicy: &deletePolicy})
appliedWork := workv1alpha1.AppliedWork{}
err := r.spokeClient.Get(ctx, types.NamespacedName{
Name: work.Name,
}, &appliedWork)
if err != nil {
return ctrl.Result{}, err
}
err = r.spokeClient.Delete(ctx, &appliedWork, &client.DeleteOptions{PropagationPolicy: &deletePolicy})
if err != nil {
klog.ErrorS(err, "failed to delete the applied Work", work.Name)
return ctrl.Result{}, err

Просмотреть файл

@ -19,6 +19,7 @@ package controllers
import (
"context"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
workv1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1"
"time"
@ -96,7 +97,7 @@ var _ = Describe("Garbage Collected", func() {
},
}
_, createWorkErr := workClient.MulticlusterV1alpha1().Works(workNamespace).Create(context.Background(), work, metav1.CreateOptions{})
createWorkErr := workClient.Create(context.Background(), work)
Expect(createWorkErr).ToNot(HaveOccurred())
})
@ -110,8 +111,12 @@ var _ = Describe("Garbage Collected", func() {
Context("A Work object with manifests has been created.", func() {
It("Should have created an AppliedWork object", func() {
Eventually(func() bool {
appliedWorkObject, err2 := workClient.MulticlusterV1alpha1().AppliedWorks().Get(context.Background(), workName, metav1.GetOptions{})
if err2 == nil {
appliedWorkObject := workv1alpha1.AppliedWork{}
err := workClient.Get(context.Background(), types.NamespacedName{
Namespace: workNamespace,
Name: workName,
}, &appliedWorkObject)
if err == nil {
return appliedWorkObject.Spec.WorkName == workName
}
return false

Просмотреть файл

@ -13,7 +13,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
workv1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1"
"sigs.k8s.io/work-api/pkg/client/clientset/versioned/fake"
)
// TestWrapper is a struct used to encapsulate the mocked dependencies needed to simulate a specific flow in logic.
@ -84,12 +83,9 @@ func generateTestWrapper() *TestWrapper {
return &TestWrapper{
mockReconciler: &FinalizeWorkReconciler{
client: test.NewMockClient(),
recorder: utils.NewFakeRecorder(2),
spokeClient: fake.NewSimpleClientset(
mockWork,
mockAppliedWork,
)},
client: test.NewMockClient(),
recorder: utils.NewFakeRecorder(2),
spokeClient: test.NewMockClient()},
mockAppliedWork: mockAppliedWork,
mockWork: mockWork,
}

Просмотреть файл

@ -27,8 +27,6 @@ import (
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
clientset "sigs.k8s.io/work-api/pkg/client/clientset/versioned"
)
const (
@ -70,11 +68,6 @@ func Start(ctx context.Context, hubCfg, spokeCfg *rest.Config, setupLog logr.Log
os.Exit(1)
}
spokeClientset, err := clientset.NewForConfig(spokeCfg)
if err != nil {
klog.Fatalf("Error building example clientset: %s", err.Error())
}
if err = newWorkStatusReconciler(
hubMgr.GetClient(),
spokeClient,
@ -102,7 +95,7 @@ func Start(ctx context.Context, hubCfg, spokeCfg *rest.Config, setupLog logr.Log
if err = (&FinalizeWorkReconciler{
client: hubMgr.GetClient(),
recorder: hubMgr.GetEventRecorderFor("WorkFinalizer_controller"),
spokeClient: spokeClientset,
spokeClient: spokeClient,
}).SetupWithManager(hubMgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "WorkFinalize")
return err

Просмотреть файл

@ -20,6 +20,7 @@ import (
"fmt"
"os"
"path/filepath"
"sigs.k8s.io/controller-runtime/pkg/client"
"testing"
. "github.com/onsi/ginkgo"
@ -34,7 +35,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"
workv1alpha1 "sigs.k8s.io/work-api/pkg/apis/v1alpha1"
workclient "sigs.k8s.io/work-api/pkg/client/clientset/versioned"
)
// These tests use Ginkgo (BDD-style Go testing framework). Refer to
@ -43,7 +43,7 @@ var (
cfg *rest.Config
// TODO: Seperate k8sClient into hub and spoke
k8sClient kubernetes.Interface
workClient workclient.Interface
workClient client.Client
dynamicClient dynamic.Interface
testEnv *envtest.Environment
setupLog = ctrl.Log.WithName("test")
@ -79,7 +79,9 @@ var _ = BeforeSuite(func(done Done) {
k8sClient, err = kubernetes.NewForConfig(cfg)
Expect(err).NotTo(HaveOccurred())
workClient, err = workclient.NewForConfig(cfg)
workClient, err = client.New(cfg, client.Options{
Scheme: scheme.Scheme,
})
Expect(err).NotTo(HaveOccurred())
dynamicClient, err = dynamic.NewForConfig(cfg)
Expect(err).NotTo(HaveOccurred())

Просмотреть файл

@ -19,6 +19,7 @@ package controllers
import (
"context"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"time"
. "github.com/onsi/ginkgo"
@ -93,13 +94,18 @@ var _ = Describe("Work Status Reconciler", func() {
},
}
_, createWorkErr := workClient.MulticlusterV1alpha1().Works(workNamespace).Create(context.Background(), work, metav1.CreateOptions{})
createWorkErr := workClient.Create(context.Background(), work)
Expect(createWorkErr).ToNot(HaveOccurred())
Eventually(func() bool {
appliedWorkObject, _ := workClient.MulticlusterV1alpha1().AppliedWorks().Get(context.Background(), workName, metav1.GetOptions{})
namespacedName := types.NamespacedName{Name: workName, Namespace: workNamespace}
return appliedWorkObject.Spec.WorkName == workName
getAppliedWork := workv1alpha1.AppliedWork{}
err := workClient.Get(context.Background(), namespacedName, &getAppliedWork)
if err == nil {
return getAppliedWork.Spec.WorkName == workName
}
return false
}, timeout, interval).Should(BeTrue())
})
@ -111,15 +117,14 @@ var _ = Describe("Work Status Reconciler", func() {
Context("Receives a request where a Work's manifest condition does not contain the metadata of an existing AppliedResourceMeta", func() {
It("Should delete the resource from the spoke cluster", func() {
Eventually(func() error {
currentWork, err := workClient.MulticlusterV1alpha1().Works(workNamespace).Get(context.Background(), workName, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
currentWork := workv1alpha1.Work{}
err := workClient.Get(context.Background(), types.NamespacedName{Name: workName, Namespace: workNamespace}, &currentWork)
Expect(err).ToNot(HaveOccurred())
currentWork.Status.ManifestConditions = []workv1alpha1.ManifestCondition{}
currentWork.Status.ManifestConditions = []workv1alpha1.ManifestCondition{}
_, err = workClient.MulticlusterV1alpha1().Works(workNamespace).Update(context.Background(), currentWork, metav1.UpdateOptions{})
return err
}, timeout, interval).ShouldNot(HaveOccurred())
err = workClient.Update(context.Background(), &currentWork)
Expect(err).ToNot(HaveOccurred())
Eventually(func() bool {
gvr := schema.GroupVersionResource{
@ -136,20 +141,20 @@ var _ = Describe("Work Status Reconciler", func() {
Context("Receives a request where a Work's manifest condition exists, but there"+
" isn't a respective AppliedResourceMeta.", func() {
It("Resource is deleted from the AppliedResources of the AppliedWork", func() {
Eventually(func() error {
currentAppliedWork, err := workClient.MulticlusterV1alpha1().AppliedWorks().Get(context.Background(), workName, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
currentAppliedWork.Status.AppliedResources = []workv1alpha1.AppliedResourceMeta{}
_, err = workClient.MulticlusterV1alpha1().AppliedWorks().Update(context.Background(), currentAppliedWork, metav1.UpdateOptions{})
return err
}, timeout, interval).ShouldNot(HaveOccurred())
appliedWork := workv1alpha1.AppliedWork{}
err := workClient.Get(context.Background(), types.NamespacedName{Name: workName, Namespace: workNamespace}, &appliedWork)
Expect(err).ToNot(HaveOccurred())
appliedWork.Status.AppliedResources = []workv1alpha1.AppliedResourceMeta{}
err = workClient.Update(context.Background(), &appliedWork)
Expect(err).ToNot(HaveOccurred())
Eventually(func() bool {
currentAppliedWork, err := workClient.MulticlusterV1alpha1().AppliedWorks().Get(context.Background(), workName, metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
err := workClient.Update(context.Background(), &appliedWork)
if err != nil {
return false
}
return len(currentAppliedWork.Status.AppliedResources) > 0
return len(appliedWork.Status.AppliedResources) > 0
}, timeout, interval).Should(BeTrue())
})
})

Просмотреть файл

@ -10,6 +10,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/json"
utilrand "k8s.io/apimachinery/pkg/util/rand"
@ -24,7 +25,7 @@ type manifestDetails struct {
}
const (
eventuallyTimeout = 10 // seconds
eventuallyTimeout = 30 // seconds
eventuallyInterval = 1 // seconds
)
@ -64,8 +65,7 @@ var _ = Describe("Work modification", func() {
WorkUpdateWithReplacedManifestsContext(
"with all manifests replaced",
[]string{
"manifests/test-deployment.yaml",
"manifests/test-service.yaml",
"manifests/test-secret.yaml",
},
[]string{
"manifests/test-configmap.yaml",
@ -95,19 +95,25 @@ var WorkCreatedContext = func(description string, manifestFiles []string) bool {
mDetails,
)
createdWork, err = createWorkResource(workObj)
err = createWork(workObj)
createdWork, err = retrieveWork(workObj.Namespace, workObj.Name)
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
err = deleteWorkResource(createdWork.Namespace, createdWork.Name)
err = deleteWorkResource(createdWork)
Expect(err).ToNot(HaveOccurred())
})
It("should have created: a respective AppliedWork, and the resources specified in the Work's manifests", func() {
By("verifying an AppliedWork was created")
Eventually(func() error {
_, err := spokeWorkClient.MulticlusterV1alpha1().AppliedWorks().Get(context.Background(), createdWork.Name, metav1.GetOptions{})
appliedWork := workapi.AppliedWork{}
err := spokeClient.Get(context.Background(), types.NamespacedName{
Namespace: createdWork.Namespace,
Name: createdWork.Name,
}, &appliedWork)
return err
}, eventuallyTimeout, eventuallyInterval).ShouldNot(HaveOccurred())
@ -145,12 +151,13 @@ var WorkCreatedWithCRDContext = func(description string, manifestFiles []string)
manifestDetails,
)
createdWork, err = createWorkResource(workObj)
err = createWork(workObj)
createdWork, err = retrieveWork(workObj.Namespace, workObj.Name)
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
err = deleteWorkResource(createdWork.Namespace, createdWork.Name)
err = deleteWorkResource(createdWork)
Expect(err).ToNot(HaveOccurred())
})
@ -182,12 +189,13 @@ var WorkUpdateWithDependencyContext = func(description string, initialManifestFi
initialManifestDetails,
)
createdWork, err = createWorkResource(workObj)
err = createWork(workObj)
createdWork, err = retrieveWork(workObj.Namespace, workObj.Name)
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
err = deleteWorkResource(createdWork.Namespace, createdWork.Name)
err = deleteWorkResource(createdWork)
Expect(err).ToNot(HaveOccurred())
})
@ -198,7 +206,7 @@ var WorkUpdateWithDependencyContext = func(description string, initialManifestFi
Expect(err).ToNot(HaveOccurred())
createdWork.Spec.Workload.Manifests = append(createdWork.Spec.Workload.Manifests, addedManifestDetails[0].Manifest, addedManifestDetails[1].Manifest)
createdWork, err = hubWorkClient.MulticlusterV1alpha1().Works(createdWork.Namespace).Update(context.Background(), createdWork, metav1.UpdateOptions{})
createdWork, err = updateWork(createdWork)
return err
}, eventuallyTimeout, eventuallyInterval).ShouldNot(HaveOccurred())
@ -240,12 +248,13 @@ var WorkUpdateWithModifiedManifestContext = func(description string, manifestFil
manifestDetails,
)
createdWork, err = createWorkResource(workObj)
err = createWork(workObj)
createdWork, err = retrieveWork(workObj.Namespace, workObj.Name)
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
err = deleteWorkResource(createdWork.Namespace, createdWork.Name)
err = deleteWorkResource(createdWork)
Expect(err).ToNot(HaveOccurred())
})
@ -265,7 +274,7 @@ var WorkUpdateWithModifiedManifestContext = func(description string, manifestFil
createdWork.Spec.Workload.Manifests[0].Object = obj
createdWork.Spec.Workload.Manifests[0].Raw = rawUpdatedManifest
createdWork, err = hubWorkClient.MulticlusterV1alpha1().Works(createdWork.Namespace).Update(context.Background(), createdWork, metav1.UpdateOptions{})
createdWork, err = updateWork(createdWork)
return err
}, eventuallyTimeout, eventuallyInterval).ShouldNot(HaveOccurred())
@ -299,32 +308,33 @@ var WorkUpdateWithReplacedManifestsContext = func(description string, originalMa
originalManifestDetails,
)
createdWork, err = createWorkResource(workObj)
err = createWork(workObj)
createdWork, err = retrieveWork(workObj.Namespace, workObj.Name)
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
err = deleteWorkResource(createdWork.Namespace, createdWork.Name)
err = deleteWorkResource(createdWork)
Expect(err).ToNot(HaveOccurred())
})
It("should have deleted the original Work's resources, and created new resources with the replaced manifests", func() {
By("getting the respective AppliedWork")
Eventually(func() int {
appliedWork, _ = spokeWorkClient.MulticlusterV1alpha1().AppliedWorks().Get(context.Background(), createdWork.Name, metav1.GetOptions{})
appliedWork, _ = retrieveAppliedWork(createdWork.Name)
return len(appliedWork.Status.AppliedResources)
}, eventuallyTimeout, eventuallyInterval).Should(Equal(len(createdWork.Spec.Workload.Manifests)))
}, eventuallyTimeout, eventuallyInterval).Should(Equal(len(originalManifestDetails)))
By("updating the Work resource with replaced manifests")
Eventually(func() error {
createdWork, err = hubWorkClient.MulticlusterV1alpha1().Works(createdWork.Namespace).Get(context.Background(), createdWork.Name, metav1.GetOptions{})
createdWork, err = retrieveWork(createdWork.Namespace, createdWork.Name)
createdWork.Spec.Workload.Manifests = nil
for _, mD := range replacedManifestDetails {
createdWork.Spec.Workload.Manifests = append(createdWork.Spec.Workload.Manifests, mD.Manifest)
}
createdWork, err = hubWorkClient.MulticlusterV1alpha1().Works(createdWork.Namespace).Update(context.Background(), createdWork, metav1.UpdateOptions{})
createdWork, err = updateWork(createdWork)
return err
}, eventuallyTimeout, eventuallyInterval).ShouldNot(HaveOccurred())
@ -376,12 +386,8 @@ var WorkDeletedContext = func(description string, manifestFiles []string) bool {
manifestDetails,
)
createdWork, err = createWorkResource(workObj)
Expect(err).ToNot(HaveOccurred())
})
AfterEach(func() {
err = deleteWorkResource(createdWork.Namespace, createdWork.Name)
err = createWork(workObj)
createdWork, err = retrieveWork(workObj.Namespace, workObj.Name)
Expect(err).ToNot(HaveOccurred())
})
@ -394,7 +400,7 @@ var WorkDeletedContext = func(description string, manifestFiles []string) bool {
}, eventuallyTimeout, eventuallyInterval).ShouldNot(HaveOccurred())
By("deleting the Work resource")
err = deleteWorkResource(createdWork.Namespace, createdWork.Name)
err = deleteWorkResource(createdWork)
Expect(err).ToNot(HaveOccurred())
By("verifying the resource was garbage collected")
@ -422,8 +428,8 @@ func createWorkObj(workName string, workNamespace string, manifestDetails []mani
return work
}
func createWorkResource(work *workapi.Work) (*workapi.Work, error) {
return hubWorkClient.MulticlusterV1alpha1().Works(work.Namespace).Create(context.Background(), work, metav1.CreateOptions{})
func createWork(work *workapi.Work) error {
return hubClient.Create(context.Background(), work)
}
func decodeUnstructured(manifest workapi.Manifest) (*unstructured.Unstructured, error) {
unstructuredObj := &unstructured.Unstructured{}
@ -431,8 +437,8 @@ func decodeUnstructured(manifest workapi.Manifest) (*unstructured.Unstructured,
return unstructuredObj, err
}
func deleteWorkResource(namespace string, name string) error {
return hubWorkClient.MulticlusterV1alpha1().Works(namespace).Delete(context.Background(), name, metav1.DeleteOptions{})
func deleteWorkResource(work *workapi.Work) error {
return hubClient.Delete(context.Background(), work)
}
func generateManifestDetails(manifestFiles []string) []manifestDetails {
var details []manifestDetails
@ -474,6 +480,32 @@ func generateManifestDetails(manifestFiles []string) []manifestDetails {
return details
}
func retrieveWork(namespace string, name string) (*workapi.Work, error) {
return hubWorkClient.MulticlusterV1alpha1().Works(namespace).Get(context.Background(), name, metav1.GetOptions{})
func retrieveAppliedWork(appliedWorkName string) (*workapi.AppliedWork, error) {
retrievedAppliedWork := workapi.AppliedWork{}
err := spokeClient.Get(context.Background(), types.NamespacedName{Name: appliedWorkName}, &retrievedAppliedWork)
if err != nil {
return &retrievedAppliedWork, err
}
return &retrievedAppliedWork, nil
}
func retrieveWork(workNamespace string, workName string) (*workapi.Work, error) {
workRetrieved := workapi.Work{}
err := hubClient.Get(context.Background(), types.NamespacedName{Namespace: workNamespace, Name: workName}, &workRetrieved)
if err != nil {
return nil, err
}
return &workRetrieved, nil
}
func updateWork(work *workapi.Work) (*workapi.Work, error) {
err := hubClient.Update(context.Background(), work)
if err != nil {
return nil, err
}
updatedWork, err := retrieveWork(work.Namespace, work.Name)
if err != nil {
return nil, err
}
return updatedWork, err
}

Просмотреть файл

@ -5,7 +5,7 @@ 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
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,
@ -18,15 +18,11 @@ package e2e
import (
"embed"
"k8s.io/apimachinery/pkg/api/meta"
"os"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
"testing"
"github.com/onsi/ginkgo"
"github.com/onsi/gomega"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apiextension "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
@ -35,22 +31,25 @@ import (
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"os"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
workclientset "sigs.k8s.io/work-api/pkg/client/clientset/versioned"
"sigs.k8s.io/work-api/pkg/apis/v1alpha1"
"testing"
)
var (
restConfig *rest.Config
restMapper meta.RESTMapper
hubWorkClient workclientset.Interface
hubClient client.Client
spokeApiExtensionClient *apiextension.Clientset
spokeDynamicClient dynamic.Interface
spokeClient client.Client
spokeKubeClient kubernetes.Interface
spokeWorkClient workclientset.Interface
spokeDynamicClient dynamic.Interface
//go:embed manifests
testManifestFiles embed.FS
@ -63,6 +62,7 @@ var (
func init() {
utilruntime.Must(scheme.AddToScheme(genericScheme))
utilruntime.Must(apiextensionsv1.AddToScheme(genericScheme))
utilruntime.Must(v1alpha1.AddToScheme(genericScheme))
}
func TestE2e(t *testing.T) {
@ -84,21 +84,25 @@ var _ = ginkgo.BeforeSuite(func() {
restConfig, err = clientcmd.BuildConfigFromFlags("", kubeconfig)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
hubWorkClient, err = workclientset.NewForConfig(restConfig)
hubClient, err = client.New(restConfig, client.Options{
Scheme: genericScheme,
})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
spokeApiExtensionClient, err = apiextension.NewForConfig(restConfig)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
spokeClient, err = client.New(restConfig, client.Options{
Scheme: genericScheme,
})
gomega.Expect(err).ToNot(gomega.HaveOccurred())
spokeDynamicClient, err = dynamic.NewForConfig(restConfig)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
spokeKubeClient, err = kubernetes.NewForConfig(restConfig)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
spokeWorkClient, err = workclientset.NewForConfig(restConfig)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
restMapper, err = apiutil.NewDynamicRESTMapper(restConfig, apiutil.WithLazyDiscovery)
gomega.Expect(err).ToNot(gomega.HaveOccurred())
})