Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add PackageRevision Approval API #2810

Merged
merged 1 commit into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions porch/api/porch/v1alpha1/types_packagerevisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
)

// +genclient
// +genclient:method=UpdateApproval,verb=update,subresource=approval,input=github.com/GoogleContainerTools/kpt/porch/api/porch/v1alpha1.PackageRevision,result=github.com/GoogleContainerTools/kpt/porch/api/porch/v1alpha1.PackageRevision
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// PackageRevision
Expand Down

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

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

56 changes: 56 additions & 0 deletions porch/apiserver/pkg/registry/porch/packagerevisions_approval.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2022 Google LLC
//
// 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 porch

import (
"context"

api "github.com/GoogleContainerTools/kpt/porch/api/porch/v1alpha1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apiserver/pkg/registry/rest"
)

type packageRevisionsApproval struct {
revisions *packageRevisions
}

var _ rest.Storage = &packageRevisionsApproval{}
var _ rest.Scoper = &packageRevisionsApproval{}
var _ rest.Getter = &packageRevisionsApproval{}
var _ rest.Updater = &packageRevisionsApproval{}

// New returns an empty object that can be used with Create and Update after request data has been put into it.
// This object must be a pointer type for use with Codec.DecodeInto([]byte, runtime.Object)
func (a *packageRevisionsApproval) New() runtime.Object {
return &api.PackageRevision{}
}

// NamespaceScoped returns true if the storage is namespaced
func (a *packageRevisionsApproval) NamespaceScoped() bool {
return true
}

func (a *packageRevisionsApproval) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) {
return a.revisions.Get(ctx, name, options)
}

// Update finds a resource in the storage and updates it. Some implementations
// may allow updates creates the object - they should set the created boolean
// to true.
func (a *packageRevisionsApproval) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) {
forceAllowCreate = false // do not allow create on update
return a.revisions.Update(ctx, name, objInfo, createValidation, updateValidation, forceAllowCreate, options)
}
11 changes: 8 additions & 3 deletions porch/apiserver/pkg/registry/porch/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func NewRESTStorage(scheme *runtime.Scheme, codecs serializer.CodecFactory, cad
},
}

packageRevisionsApproval := &packageRevisionsApproval{
revisions: packageRevisions,
}

packageRevisionResources := &packageRevisionResources{
TableConvertor: rest.NewDefaultTableConvertor(porch.Resource("packagerevisionresources")),
packageCommon: packageCommon{
Expand All @@ -54,9 +58,10 @@ func NewRESTStorage(scheme *runtime.Scheme, codecs serializer.CodecFactory, cad

group.VersionedResourcesStorageMap = map[string]map[string]rest.Storage{
"v1alpha1": {
"packagerevisions": packageRevisions,
"packagerevisionresources": packageRevisionResources,
"functions": functions,
"packagerevisions": packageRevisions,
"packagerevisions/approval": packageRevisionsApproval,
"packagerevisionresources": packageRevisionResources,
"functions": functions,
},
}

Expand Down