Skip to content
This repository was archived by the owner on Apr 25, 2024. It is now read-only.

Commit 97db1f8

Browse files
authored
Merge pull request #128 from FabianKramm/master
chore: update k8s deps to v1.21.1
2 parents fb11228 + b08f854 commit 97db1f8

File tree

2,381 files changed

+298153
-45333
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,381 files changed

+298153
-45333
lines changed

cmd/kiosk/main.go

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ package main
1818

1919
import (
2020
"context"
21+
"fmt"
22+
apiserver "github.com/loft-sh/apiserver/pkg/server"
2123
"github.com/loft-sh/kiosk/pkg/apis"
2224
"github.com/loft-sh/kiosk/pkg/apis/tenancy"
2325
tenancyv1alpha1 "github.com/loft-sh/kiosk/pkg/apis/tenancy/v1alpha1"
24-
"github.com/loft-sh/kiosk/pkg/apiserver"
2526
_ "github.com/loft-sh/kiosk/pkg/apiserver/registry"
2627
"github.com/loft-sh/kiosk/pkg/leaderelection"
2728
"github.com/loft-sh/kiosk/pkg/manager/blockingcacheclient"
@@ -40,8 +41,10 @@ import (
4041
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
4142
"math/rand"
4243
"os"
44+
"path/filepath"
4345
client2 "sigs.k8s.io/controller-runtime/pkg/client"
4446
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
47+
"strconv"
4548
"time"
4649

4750
configv1alpha1 "github.com/loft-sh/kiosk/pkg/apis/config/v1alpha1"
@@ -120,7 +123,7 @@ func main() {
120123

121124
// create the manager
122125
mgr, err := ctrl.NewManager(config, ctrl.Options{
123-
ClientBuilder: blockingcacheclient.NewCacheClientBuilder(),
126+
NewClient: blockingcacheclient.NewCacheClient,
124127
Scheme: scheme,
125128
MetricsBindAddress: ":8080",
126129
CertDir: certhelper.WebhookCertFolder,
@@ -170,25 +173,39 @@ func main() {
170173

171174
// Start the api server
172175
go func() {
173-
version := "v0"
174176
if os.Getenv("SERVER_SIDE_APPLY_ENABLED") != "true" {
175177
err := featureutil.DefaultMutableFeatureGate.Set(string(genericfeatures.ServerSideApply) + "=false")
176178
if err != nil {
177179
panic(err)
178180
}
179181
}
180182

181-
err = apiserver.StartApiServerWithOptions(&apiserver.StartOptions{
182-
Apis: apis.GetAllApiBuilders(),
183-
Openapidefs: openapi.GetOpenAPIDefinitions,
184-
Title: "Api",
185-
Version: version,
183+
err = apiserver.StartAPIServer(&apiserver.StartOptions{
184+
Apis: apis.GetAllApiBuilders(),
185+
GetOpenAPIDefinitions: openapi.GetOpenAPIDefinitions,
186+
TweakServerOptions: func(o *apiserver.ServerOptions) {
187+
o.DisableWebhooks = os.Getenv("DISABLE_WEBHOOKS") == "true"
188+
o.RecommendedOptions.SecureServing.ServerCert.CertKey.CertFile = filepath.Join(certhelper.APIServiceCertFolder, "tls.crt")
189+
o.RecommendedOptions.SecureServing.ServerCert.CertKey.KeyFile = filepath.Join(certhelper.APIServiceCertFolder, "tls.key")
190+
191+
var err error
192+
apiServicePort := 8443
193+
apiServicePortEnv := os.Getenv("APISERVICE_PORT")
194+
if apiServicePortEnv != "" {
195+
apiServicePort, err = strconv.Atoi(apiServicePortEnv)
196+
if err != nil {
197+
panic(fmt.Sprintf("parsing api service port %s: %v", apiServicePortEnv, err))
198+
}
199+
}
200+
201+
o.RecommendedOptions.SecureServing.BindPort = apiServicePort
202+
},
186203
})
187204
if err != nil {
188205
panic(err)
189206
}
190207
}()
191-
208+
192209
// start leader election for controllers
193210
go func() {
194211
err = leaderelection.StartLeaderElection(ctx, scheme, config, func() error {
@@ -209,7 +226,7 @@ func main() {
209226
os.Exit(1)
210227
}
211228
}
212-
229+
213230
// Register generic controllers
214231
err = controllers.Register(mgr)
215232
if err != nil {
@@ -221,7 +238,7 @@ func main() {
221238
if err != nil {
222239
return errors.Wrap(err, "unable to register quota controller")
223240
}
224-
241+
225242
return nil
226243
})
227244
if err != nil {

gen/cmd/apis/main.go

Lines changed: 249 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"os"
2121
"runtime"
2222

23-
"github.com/loft-sh/kiosk/gen/cmd/apis/template"
23+
"github.com/loft-sh/apiserver/pkg/generate"
2424
"k8s.io/gengo/args"
2525
"k8s.io/klog"
2626
)
@@ -35,13 +35,259 @@ func main() {
3535
// Override defaults.
3636
arguments.OutputFileBaseName = "zz_generated.api.register"
3737

38+
generate.UnversionedAPIImports = append(generate.UnversionedAPIImports, "sigs.k8s.io/controller-runtime/pkg/client")
39+
generate.UnversionedAPITemplate = UnversionedAPITemplate
40+
3841
// Custom args.
39-
customArgs := &template.CustomArgs{}
42+
customArgs := &generate.CustomArgs{}
4043
arguments.CustomArgs = customArgs
4144

42-
g := template.Gen{}
45+
g := generate.Gen{}
4346
if err := g.Execute(arguments); err != nil {
4447
klog.Fatalf("Error: %v", err)
4548
}
4649
klog.V(2).Info("Completed successfully.")
4750
}
51+
52+
var UnversionedAPITemplate = `
53+
type NewRESTFunc func(cachedClient client.Client, uncachedClient client.Client, scheme *runtime.Scheme) rest.Storage
54+
55+
var (
56+
{{ range $api := .UnversionedResources -}}
57+
{{ if $api.REST -}}
58+
{{$api.Group|public}}{{$api.Kind}}Storage = builders.NewApiResourceWithStorage( // Resource status endpoint
59+
Internal{{ $api.Kind }},
60+
func() runtime.Object { return &{{ $api.Kind }}{} }, // Register versioned resource
61+
func() runtime.Object { return &{{ $api.Kind }}List{} }, // Register versioned resource list
62+
New{{ $api.REST }},
63+
)
64+
New{{ $api.REST }} = func(getter generic.RESTOptionsGetter) rest.Storage {
65+
return New{{ $api.REST }}Func(CachedClient, UncachedClient, Scheme)
66+
}
67+
New{{ $api.REST }}Func NewRESTFunc
68+
{{ else -}}
69+
{{$api.Group|public}}{{$api.Kind}}Storage = builders.NewApiResource( // Resource status endpoint
70+
Internal{{ $api.Kind }},
71+
func() runtime.Object { return &{{ $api.Kind }}{} }, // Register versioned resource
72+
func() runtime.Object { return &{{ $api.Kind }}List{} }, // Register versioned resource list
73+
&{{ $api.Strategy }}{builders.StorageStrategySingleton},
74+
)
75+
{{ end -}}
76+
{{ end -}}
77+
{{ range $api := .UnversionedResources -}}
78+
{{- if $api.ShortName -}}
79+
Internal{{ $api.Kind }} = builders.NewInternalResourceWithShortcuts(
80+
{{ else -}}
81+
Internal{{ $api.Kind }} = builders.NewInternalResource(
82+
{{ end -}}
83+
"{{ $api.Resource }}",
84+
"{{ $api.Kind }}",
85+
func() runtime.Object { return &{{ $api.Kind }}{} },
86+
func() runtime.Object { return &{{ $api.Kind }}List{} },
87+
{{ if $api.ShortName -}}
88+
[]string{"{{ $api.ShortName }}"},
89+
[]string{"aggregation"}, // TBD
90+
{{ end -}}
91+
)
92+
Internal{{ $api.Kind }}Status = builders.NewInternalResourceStatus(
93+
"{{ $api.Resource }}",
94+
"{{ $api.Kind }}Status",
95+
func() runtime.Object { return &{{ $api.Kind }}{} },
96+
func() runtime.Object { return &{{ $api.Kind }}List{} },
97+
)
98+
{{ range $subresource := .Subresources -}}
99+
Internal{{$subresource.Kind}}REST = builders.NewInternalSubresource(
100+
"{{$subresource.Resource}}", "{{$subresource.Request}}", "{{$subresource.Path}}",
101+
func() runtime.Object { return &{{$subresource.Request}}{} },
102+
)
103+
New{{$subresource.Kind}}REST = func(getter generic.RESTOptionsGetter) rest.Storage {
104+
return New{{$subresource.Kind}}RESTFunc(CachedClient, UncachedClient, Scheme)
105+
}
106+
New{{$subresource.Kind}}RESTFunc NewRESTFunc
107+
{{ end -}}
108+
{{ end -}}
109+
110+
// Registered resources and subresources
111+
ApiVersion = builders.NewApiGroup("{{.Group}}.{{.Domain}}").WithKinds(
112+
{{ range $api := .UnversionedResources -}}
113+
Internal{{$api.Kind}},
114+
Internal{{$api.Kind}}Status,
115+
{{ range $subresource := $api.Subresources -}}
116+
Internal{{$subresource.Kind}}REST,
117+
{{ end -}}
118+
{{ end -}}
119+
)
120+
121+
// Required by code generated by go2idl
122+
AddToScheme = (&runtime.SchemeBuilder{
123+
ApiVersion.SchemeBuilder.AddToScheme,
124+
RegisterDefaults,
125+
}).AddToScheme
126+
SchemeBuilder = ApiVersion.SchemeBuilder
127+
localSchemeBuilder = &SchemeBuilder
128+
SchemeGroupVersion = ApiVersion.GroupVersion
129+
)
130+
131+
// Required by code generated by go2idl
132+
// Kind takes an unqualified kind and returns a Group qualified GroupKind
133+
func Kind(kind string) schema.GroupKind {
134+
return SchemeGroupVersion.WithKind(kind).GroupKind()
135+
}
136+
137+
// Required by code generated by go2idl
138+
// Resource takes an unqualified resource and returns a Group qualified GroupResource
139+
func Resource(resource string) schema.GroupResource {
140+
return SchemeGroupVersion.WithResource(resource).GroupResource()
141+
}
142+
143+
{{ range $a := .Aliases -}}
144+
type {{ $a.Name }} {{ $a.UnderlyingTypeName }}
145+
{{ end -}}
146+
147+
{{ range $s := .Structs -}}
148+
{{ if $s.GenUnversioned -}}
149+
{{ if $s.GenClient }}// +genclient{{end}}
150+
{{ if $s.GenClient }}// +genclient{{ if $s.NonNamespaced }}:nonNamespaced{{end}}{{end}}
151+
{{ if $s.GenDeepCopy }}// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object{{end}}
152+
153+
type {{ $s.Name }} struct {
154+
{{ range $f := $s.Fields -}}
155+
{{ $f.Name }} {{ $f.UnversionedType }}
156+
{{ end -}}
157+
}
158+
{{ end -}}
159+
{{ end -}}
160+
161+
{{ range $api := .UnversionedResources -}}
162+
//
163+
// {{.Kind}} Functions and Structs
164+
//
165+
// +k8s:deepcopy-gen=false
166+
type {{.Strategy}} struct {
167+
builders.DefaultStorageStrategy
168+
}
169+
170+
// +k8s:deepcopy-gen=false
171+
type {{.StatusStrategy}} struct {
172+
builders.DefaultStatusStorageStrategy
173+
}
174+
175+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
176+
177+
type {{$api.Kind}}List struct {
178+
metav1.TypeMeta
179+
metav1.ListMeta
180+
Items []{{$api.Kind}}
181+
}
182+
183+
{{ range $subresource := $api.Subresources -}}
184+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
185+
186+
type {{$subresource.Request}}List struct {
187+
metav1.TypeMeta
188+
metav1.ListMeta
189+
Items []{{$subresource.Request}}
190+
}
191+
{{ end -}}
192+
193+
func ({{$api.Kind}}) NewStatus() interface{} {
194+
return {{$api.Kind}}Status{}
195+
}
196+
197+
func (pc *{{$api.Kind}}) GetStatus() interface{} {
198+
return pc.Status
199+
}
200+
201+
func (pc *{{$api.Kind}}) SetStatus(s interface{}) {
202+
pc.Status = s.({{$api.Kind}}Status)
203+
}
204+
205+
func (pc *{{$api.Kind}}) GetSpec() interface{} {
206+
return pc.Spec
207+
}
208+
209+
func (pc *{{$api.Kind}}) SetSpec(s interface{}) {
210+
pc.Spec = s.({{$api.Kind}}Spec)
211+
}
212+
213+
func (pc *{{$api.Kind}}) GetObjectMeta() *metav1.ObjectMeta {
214+
return &pc.ObjectMeta
215+
}
216+
217+
func (pc *{{$api.Kind}}) SetGeneration(generation int64) {
218+
pc.ObjectMeta.Generation = generation
219+
}
220+
221+
func (pc {{$api.Kind}}) GetGeneration() int64 {
222+
return pc.ObjectMeta.Generation
223+
}
224+
225+
// Registry is an interface for things that know how to store {{.Kind}}.
226+
// +k8s:deepcopy-gen=false
227+
type {{.Kind}}Registry interface {
228+
List{{.Kind}}s(ctx context.Context, options *internalversion.ListOptions) (*{{.Kind}}List, error)
229+
Get{{.Kind}}(ctx context.Context, id string, options *metav1.GetOptions) (*{{.Kind}}, error)
230+
Create{{.Kind}}(ctx context.Context, id *{{.Kind}}) (*{{.Kind}}, error)
231+
Update{{.Kind}}(ctx context.Context, id *{{.Kind}}) (*{{.Kind}}, error)
232+
Delete{{.Kind}}(ctx context.Context, id string) (bool, error)
233+
}
234+
235+
// NewRegistry returns a new Registry interface for the given Storage. Any mismatched types will panic.
236+
func New{{.Kind}}Registry(sp builders.StandardStorageProvider) {{.Kind}}Registry {
237+
return &storage{{.Kind}}{sp}
238+
}
239+
240+
// Implement Registry
241+
// storage puts strong typing around storage calls
242+
// +k8s:deepcopy-gen=false
243+
type storage{{.Kind}} struct {
244+
builders.StandardStorageProvider
245+
}
246+
247+
func (s *storage{{.Kind}}) List{{.Kind}}s(ctx context.Context, options *internalversion.ListOptions) (*{{.Kind}}List, error) {
248+
if options != nil && options.FieldSelector != nil && !options.FieldSelector.Empty() {
249+
return nil, fmt.Errorf("field selector not supported yet")
250+
}
251+
st := s.GetStandardStorage()
252+
obj, err := st.List(ctx, options)
253+
if err != nil {
254+
return nil, err
255+
}
256+
return obj.(*{{.Kind}}List), err
257+
}
258+
259+
func (s *storage{{.Kind}}) Get{{.Kind}}(ctx context.Context, id string, options *metav1.GetOptions) (*{{.Kind}}, error) {
260+
st := s.GetStandardStorage()
261+
obj, err := st.Get(ctx, id, options)
262+
if err != nil {
263+
return nil, err
264+
}
265+
return obj.(*{{.Kind}}), nil
266+
}
267+
268+
func (s *storage{{.Kind}}) Create{{.Kind}}(ctx context.Context, object *{{.Kind}}) (*{{.Kind}}, error) {
269+
st := s.GetStandardStorage()
270+
obj, err := st.Create(ctx, object, nil, &metav1.CreateOptions{})
271+
if err != nil {
272+
return nil, err
273+
}
274+
return obj.(*{{.Kind}}), nil
275+
}
276+
277+
func (s *storage{{.Kind}}) Update{{.Kind}}(ctx context.Context, object *{{.Kind}}) (*{{.Kind}}, error) {
278+
st := s.GetStandardStorage()
279+
obj, _, err := st.Update(ctx, object.Name, rest.DefaultUpdatedObjectInfo(object), nil, nil, false, &metav1.UpdateOptions{})
280+
if err != nil {
281+
return nil, err
282+
}
283+
return obj.(*{{.Kind}}), nil
284+
}
285+
286+
func (s *storage{{.Kind}}) Delete{{.Kind}}(ctx context.Context, id string) (bool, error) {
287+
st := s.GetStandardStorage()
288+
_, sync, err := st.Delete(ctx, id, nil, &metav1.DeleteOptions{})
289+
return sync, err
290+
}
291+
292+
{{ end -}}
293+
`

0 commit comments

Comments
 (0)