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

Commit

Permalink
Merge pull request #128 from FabianKramm/master
Browse files Browse the repository at this point in the history
chore: update k8s deps to v1.21.1
  • Loading branch information
FabianKramm authored Jun 8, 2021
2 parents fb11228 + b08f854 commit 97db1f8
Show file tree
Hide file tree
Showing 2,381 changed files with 298,153 additions and 45,333 deletions.
39 changes: 28 additions & 11 deletions cmd/kiosk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ package main

import (
"context"
"fmt"
apiserver "github.com/loft-sh/apiserver/pkg/server"
"github.com/loft-sh/kiosk/pkg/apis"
"github.com/loft-sh/kiosk/pkg/apis/tenancy"
tenancyv1alpha1 "github.com/loft-sh/kiosk/pkg/apis/tenancy/v1alpha1"
"github.com/loft-sh/kiosk/pkg/apiserver"
_ "github.com/loft-sh/kiosk/pkg/apiserver/registry"
"github.com/loft-sh/kiosk/pkg/leaderelection"
"github.com/loft-sh/kiosk/pkg/manager/blockingcacheclient"
Expand All @@ -40,8 +41,10 @@ import (
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
"math/rand"
"os"
"path/filepath"
client2 "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/manager/signals"
"strconv"
"time"

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

// create the manager
mgr, err := ctrl.NewManager(config, ctrl.Options{
ClientBuilder: blockingcacheclient.NewCacheClientBuilder(),
NewClient: blockingcacheclient.NewCacheClient,
Scheme: scheme,
MetricsBindAddress: ":8080",
CertDir: certhelper.WebhookCertFolder,
Expand Down Expand Up @@ -170,25 +173,39 @@ func main() {

// Start the api server
go func() {
version := "v0"
if os.Getenv("SERVER_SIDE_APPLY_ENABLED") != "true" {
err := featureutil.DefaultMutableFeatureGate.Set(string(genericfeatures.ServerSideApply) + "=false")
if err != nil {
panic(err)
}
}

err = apiserver.StartApiServerWithOptions(&apiserver.StartOptions{
Apis: apis.GetAllApiBuilders(),
Openapidefs: openapi.GetOpenAPIDefinitions,
Title: "Api",
Version: version,
err = apiserver.StartAPIServer(&apiserver.StartOptions{
Apis: apis.GetAllApiBuilders(),
GetOpenAPIDefinitions: openapi.GetOpenAPIDefinitions,
TweakServerOptions: func(o *apiserver.ServerOptions) {
o.DisableWebhooks = os.Getenv("DISABLE_WEBHOOKS") == "true"
o.RecommendedOptions.SecureServing.ServerCert.CertKey.CertFile = filepath.Join(certhelper.APIServiceCertFolder, "tls.crt")
o.RecommendedOptions.SecureServing.ServerCert.CertKey.KeyFile = filepath.Join(certhelper.APIServiceCertFolder, "tls.key")

var err error
apiServicePort := 8443
apiServicePortEnv := os.Getenv("APISERVICE_PORT")
if apiServicePortEnv != "" {
apiServicePort, err = strconv.Atoi(apiServicePortEnv)
if err != nil {
panic(fmt.Sprintf("parsing api service port %s: %v", apiServicePortEnv, err))
}
}

o.RecommendedOptions.SecureServing.BindPort = apiServicePort
},
})
if err != nil {
panic(err)
}
}()

// start leader election for controllers
go func() {
err = leaderelection.StartLeaderElection(ctx, scheme, config, func() error {
Expand All @@ -209,7 +226,7 @@ func main() {
os.Exit(1)
}
}

// Register generic controllers
err = controllers.Register(mgr)
if err != nil {
Expand All @@ -221,7 +238,7 @@ func main() {
if err != nil {
return errors.Wrap(err, "unable to register quota controller")
}

return nil
})
if err != nil {
Expand Down
252 changes: 249 additions & 3 deletions gen/cmd/apis/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"os"
"runtime"

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

generate.UnversionedAPIImports = append(generate.UnversionedAPIImports, "sigs.k8s.io/controller-runtime/pkg/client")
generate.UnversionedAPITemplate = UnversionedAPITemplate

// Custom args.
customArgs := &template.CustomArgs{}
customArgs := &generate.CustomArgs{}
arguments.CustomArgs = customArgs

g := template.Gen{}
g := generate.Gen{}
if err := g.Execute(arguments); err != nil {
klog.Fatalf("Error: %v", err)
}
klog.V(2).Info("Completed successfully.")
}

var UnversionedAPITemplate = `
type NewRESTFunc func(cachedClient client.Client, uncachedClient client.Client, scheme *runtime.Scheme) rest.Storage
var (
{{ range $api := .UnversionedResources -}}
{{ if $api.REST -}}
{{$api.Group|public}}{{$api.Kind}}Storage = builders.NewApiResourceWithStorage( // Resource status endpoint
Internal{{ $api.Kind }},
func() runtime.Object { return &{{ $api.Kind }}{} }, // Register versioned resource
func() runtime.Object { return &{{ $api.Kind }}List{} }, // Register versioned resource list
New{{ $api.REST }},
)
New{{ $api.REST }} = func(getter generic.RESTOptionsGetter) rest.Storage {
return New{{ $api.REST }}Func(CachedClient, UncachedClient, Scheme)
}
New{{ $api.REST }}Func NewRESTFunc
{{ else -}}
{{$api.Group|public}}{{$api.Kind}}Storage = builders.NewApiResource( // Resource status endpoint
Internal{{ $api.Kind }},
func() runtime.Object { return &{{ $api.Kind }}{} }, // Register versioned resource
func() runtime.Object { return &{{ $api.Kind }}List{} }, // Register versioned resource list
&{{ $api.Strategy }}{builders.StorageStrategySingleton},
)
{{ end -}}
{{ end -}}
{{ range $api := .UnversionedResources -}}
{{- if $api.ShortName -}}
Internal{{ $api.Kind }} = builders.NewInternalResourceWithShortcuts(
{{ else -}}
Internal{{ $api.Kind }} = builders.NewInternalResource(
{{ end -}}
"{{ $api.Resource }}",
"{{ $api.Kind }}",
func() runtime.Object { return &{{ $api.Kind }}{} },
func() runtime.Object { return &{{ $api.Kind }}List{} },
{{ if $api.ShortName -}}
[]string{"{{ $api.ShortName }}"},
[]string{"aggregation"}, // TBD
{{ end -}}
)
Internal{{ $api.Kind }}Status = builders.NewInternalResourceStatus(
"{{ $api.Resource }}",
"{{ $api.Kind }}Status",
func() runtime.Object { return &{{ $api.Kind }}{} },
func() runtime.Object { return &{{ $api.Kind }}List{} },
)
{{ range $subresource := .Subresources -}}
Internal{{$subresource.Kind}}REST = builders.NewInternalSubresource(
"{{$subresource.Resource}}", "{{$subresource.Request}}", "{{$subresource.Path}}",
func() runtime.Object { return &{{$subresource.Request}}{} },
)
New{{$subresource.Kind}}REST = func(getter generic.RESTOptionsGetter) rest.Storage {
return New{{$subresource.Kind}}RESTFunc(CachedClient, UncachedClient, Scheme)
}
New{{$subresource.Kind}}RESTFunc NewRESTFunc
{{ end -}}
{{ end -}}
// Registered resources and subresources
ApiVersion = builders.NewApiGroup("{{.Group}}.{{.Domain}}").WithKinds(
{{ range $api := .UnversionedResources -}}
Internal{{$api.Kind}},
Internal{{$api.Kind}}Status,
{{ range $subresource := $api.Subresources -}}
Internal{{$subresource.Kind}}REST,
{{ end -}}
{{ end -}}
)
// Required by code generated by go2idl
AddToScheme = (&runtime.SchemeBuilder{
ApiVersion.SchemeBuilder.AddToScheme,
RegisterDefaults,
}).AddToScheme
SchemeBuilder = ApiVersion.SchemeBuilder
localSchemeBuilder = &SchemeBuilder
SchemeGroupVersion = ApiVersion.GroupVersion
)
// Required by code generated by go2idl
// Kind takes an unqualified kind and returns a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}
// Required by code generated by go2idl
// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
{{ range $a := .Aliases -}}
type {{ $a.Name }} {{ $a.UnderlyingTypeName }}
{{ end -}}
{{ range $s := .Structs -}}
{{ if $s.GenUnversioned -}}
{{ if $s.GenClient }}// +genclient{{end}}
{{ if $s.GenClient }}// +genclient{{ if $s.NonNamespaced }}:nonNamespaced{{end}}{{end}}
{{ if $s.GenDeepCopy }}// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object{{end}}
type {{ $s.Name }} struct {
{{ range $f := $s.Fields -}}
{{ $f.Name }} {{ $f.UnversionedType }}
{{ end -}}
}
{{ end -}}
{{ end -}}
{{ range $api := .UnversionedResources -}}
//
// {{.Kind}} Functions and Structs
//
// +k8s:deepcopy-gen=false
type {{.Strategy}} struct {
builders.DefaultStorageStrategy
}
// +k8s:deepcopy-gen=false
type {{.StatusStrategy}} struct {
builders.DefaultStatusStorageStrategy
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type {{$api.Kind}}List struct {
metav1.TypeMeta
metav1.ListMeta
Items []{{$api.Kind}}
}
{{ range $subresource := $api.Subresources -}}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type {{$subresource.Request}}List struct {
metav1.TypeMeta
metav1.ListMeta
Items []{{$subresource.Request}}
}
{{ end -}}
func ({{$api.Kind}}) NewStatus() interface{} {
return {{$api.Kind}}Status{}
}
func (pc *{{$api.Kind}}) GetStatus() interface{} {
return pc.Status
}
func (pc *{{$api.Kind}}) SetStatus(s interface{}) {
pc.Status = s.({{$api.Kind}}Status)
}
func (pc *{{$api.Kind}}) GetSpec() interface{} {
return pc.Spec
}
func (pc *{{$api.Kind}}) SetSpec(s interface{}) {
pc.Spec = s.({{$api.Kind}}Spec)
}
func (pc *{{$api.Kind}}) GetObjectMeta() *metav1.ObjectMeta {
return &pc.ObjectMeta
}
func (pc *{{$api.Kind}}) SetGeneration(generation int64) {
pc.ObjectMeta.Generation = generation
}
func (pc {{$api.Kind}}) GetGeneration() int64 {
return pc.ObjectMeta.Generation
}
// Registry is an interface for things that know how to store {{.Kind}}.
// +k8s:deepcopy-gen=false
type {{.Kind}}Registry interface {
List{{.Kind}}s(ctx context.Context, options *internalversion.ListOptions) (*{{.Kind}}List, error)
Get{{.Kind}}(ctx context.Context, id string, options *metav1.GetOptions) (*{{.Kind}}, error)
Create{{.Kind}}(ctx context.Context, id *{{.Kind}}) (*{{.Kind}}, error)
Update{{.Kind}}(ctx context.Context, id *{{.Kind}}) (*{{.Kind}}, error)
Delete{{.Kind}}(ctx context.Context, id string) (bool, error)
}
// NewRegistry returns a new Registry interface for the given Storage. Any mismatched types will panic.
func New{{.Kind}}Registry(sp builders.StandardStorageProvider) {{.Kind}}Registry {
return &storage{{.Kind}}{sp}
}
// Implement Registry
// storage puts strong typing around storage calls
// +k8s:deepcopy-gen=false
type storage{{.Kind}} struct {
builders.StandardStorageProvider
}
func (s *storage{{.Kind}}) List{{.Kind}}s(ctx context.Context, options *internalversion.ListOptions) (*{{.Kind}}List, error) {
if options != nil && options.FieldSelector != nil && !options.FieldSelector.Empty() {
return nil, fmt.Errorf("field selector not supported yet")
}
st := s.GetStandardStorage()
obj, err := st.List(ctx, options)
if err != nil {
return nil, err
}
return obj.(*{{.Kind}}List), err
}
func (s *storage{{.Kind}}) Get{{.Kind}}(ctx context.Context, id string, options *metav1.GetOptions) (*{{.Kind}}, error) {
st := s.GetStandardStorage()
obj, err := st.Get(ctx, id, options)
if err != nil {
return nil, err
}
return obj.(*{{.Kind}}), nil
}
func (s *storage{{.Kind}}) Create{{.Kind}}(ctx context.Context, object *{{.Kind}}) (*{{.Kind}}, error) {
st := s.GetStandardStorage()
obj, err := st.Create(ctx, object, nil, &metav1.CreateOptions{})
if err != nil {
return nil, err
}
return obj.(*{{.Kind}}), nil
}
func (s *storage{{.Kind}}) Update{{.Kind}}(ctx context.Context, object *{{.Kind}}) (*{{.Kind}}, error) {
st := s.GetStandardStorage()
obj, _, err := st.Update(ctx, object.Name, rest.DefaultUpdatedObjectInfo(object), nil, nil, false, &metav1.UpdateOptions{})
if err != nil {
return nil, err
}
return obj.(*{{.Kind}}), nil
}
func (s *storage{{.Kind}}) Delete{{.Kind}}(ctx context.Context, id string) (bool, error) {
st := s.GetStandardStorage()
_, sync, err := st.Delete(ctx, id, nil, &metav1.DeleteOptions{})
return sync, err
}
{{ end -}}
`
Loading

0 comments on commit 97db1f8

Please sign in to comment.