-
Notifications
You must be signed in to change notification settings - Fork 472
/
storage.go
114 lines (92 loc) · 3.78 KB
/
storage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package storage
import (
"context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/registry/generic"
genericregistry "k8s.io/apiserver/pkg/registry/generic/registry"
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/apiserver/pkg/storage"
"github.com/gardener/gardener/pkg/apis/seedmanagement"
"github.com/gardener/gardener/pkg/apiserver/registry/seedmanagement/managedseed"
)
// REST implements a RESTStorage for ManagedSeed.
type REST struct {
*genericregistry.Store
}
// ManagedSeedStorage implements the storage for ManagedSeeds and their status subresource.
type ManagedSeedStorage struct {
ManagedSeed *REST
Status *StatusREST
}
// NewStorage creates a new ManagedSeedStorage object.
func NewStorage(optsGetter generic.RESTOptionsGetter) ManagedSeedStorage {
managedSeedRest, managedSeedStatusRest := NewREST(optsGetter)
return ManagedSeedStorage{
ManagedSeed: managedSeedRest,
Status: managedSeedStatusRest,
}
}
// NewREST returns a RESTStorage object that will work with ManagedSeed objects.
func NewREST(optsGetter generic.RESTOptionsGetter) (*REST, *StatusREST) {
strategy := managedseed.NewStrategy()
statusStrategy := managedseed.NewStatusStrategy()
store := &genericregistry.Store{
NewFunc: func() runtime.Object { return &seedmanagement.ManagedSeed{} },
NewListFunc: func() runtime.Object { return &seedmanagement.ManagedSeedList{} },
PredicateFunc: managedseed.MatchManagedSeed,
DefaultQualifiedResource: seedmanagement.Resource("managedseeds"),
SingularQualifiedResource: seedmanagement.Resource("managedseed"),
EnableGarbageCollection: true,
CreateStrategy: strategy,
UpdateStrategy: strategy,
DeleteStrategy: strategy,
TableConvertor: newTableConvertor(),
}
options := &generic.StoreOptions{
RESTOptions: optsGetter,
AttrFunc: managedseed.GetAttrs,
TriggerFunc: map[string]storage.IndexerFunc{seedmanagement.ManagedSeedShootName: managedseed.ShootNameTriggerFunc},
}
if err := store.CompleteWithOptions(options); err != nil {
panic(err)
}
statusStore := *store
statusStore.UpdateStrategy = statusStrategy
return &REST{store}, &StatusREST{store: &statusStore}
}
// StatusREST implements the REST endpoint for changing the status of a ManagedSeed.
type StatusREST struct {
store *genericregistry.Store
}
var (
_ rest.Storage = &StatusREST{}
_ rest.Getter = &StatusREST{}
_ rest.Updater = &StatusREST{}
)
// New creates a new (empty) internal ManagedSeed object.
func (r *StatusREST) New() runtime.Object {
return &seedmanagement.ManagedSeed{}
}
// Destroy cleans up its resources on shutdown.
func (r *StatusREST) Destroy() {
// Given that underlying store is shared with REST,
// we don't destroy it here explicitly.
}
// Get retrieves the object from the storage. It is required to support Patch.
func (r *StatusREST) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
return r.store.Get(ctx, name, options)
}
// Update alters the status subset of an object.
func (r *StatusREST) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) {
return r.store.Update(ctx, name, objInfo, createValidation, updateValidation, forceAllowCreate, options)
}
// Implement ShortNamesProvider
var _ rest.ShortNamesProvider = &REST{}
// ShortNames implements the ShortNamesProvider interface. Returns a list of short names for a resource.
func (r *REST) ShortNames() []string {
return []string{"ms"}
}