Skip to content

Commit

Permalink
Fix build errors
Browse files Browse the repository at this point in the history
  • Loading branch information
efiacor committed Mar 25, 2024
1 parent 5a0c514 commit 0e92b10
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 41 deletions.
14 changes: 7 additions & 7 deletions func/internal/podevaluator.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func NewPodEvaluator(namespace, wrapperServerImage string, interval, ttl time.Du
err = pe.podCacheManager.warmupCache(podTTLConfig)
// If we can't warm up the cache, we can still proceed without it.
if err != nil {
klog.Warningf("unable to warm up the pod cache: %w", err)
klog.Warningf("unable to warm up the pod cache: %v", err)
}
return pe, nil
}
Expand Down Expand Up @@ -211,7 +211,7 @@ func (pcm *podCacheManager) warmupCache(podTTLConfig string) error {

ttl, err := time.ParseDuration(ttlStr)
if err != nil {
klog.Warningf("unable to parse duration from the config file for function %v: %w", fnImage, err)
klog.Warningf("unable to parse duration from the config file for function %v: %v", fnImage, err)
ttl = pcm.podTTL
}

Expand Down Expand Up @@ -320,7 +320,7 @@ func (pcm *podCacheManager) garbageCollector() {
podList := &corev1.PodList{}
err = pcm.podManager.kubeClient.List(context.Background(), podList, client.InNamespace(pcm.podManager.namespace))
if err != nil {
klog.Warningf("unable to list pods in namespace %v: %w", pcm.podManager.namespace, err)
klog.Warningf("unable to list pods in namespace %v: %v", pcm.podManager.namespace, err)
return
}
for i, pod := range podList.Items {
Expand All @@ -339,7 +339,7 @@ func (pcm *podCacheManager) garbageCollector() {
// If the annotation is ill-formatted, we patch it with the current time and will try to GC it later.
// This should not happen, but if it happens, we give another TTL before deleting it.
if err != nil {
klog.Warningf("unable to convert the Unix time string to int64: %w", err)
klog.Warningf("unable to convert the Unix time string to int64: %v", err)
go patchPodWithUnixTimeAnnotation(pcm.podManager.kubeClient, client.ObjectKeyFromObject(&pod), pcm.podTTL)
continue
}
Expand All @@ -350,7 +350,7 @@ func (pcm *podCacheManager) garbageCollector() {
klog.Infof("deleting pod %v/%v", po.Namespace, po.Name)
err := pcm.podManager.kubeClient.Delete(context.Background(), &po)
if err != nil {
klog.Warningf("unable to delete pod %v/%v: %w", po.Namespace, po.Name, err)
klog.Warningf("unable to delete pod %v/%v: %v", po.Namespace, po.Name, err)
}
}(podList.Items[i])

Expand Down Expand Up @@ -501,7 +501,7 @@ func (pm *podManager) retrieveOrCreatePod(ctx context.Context, image string, ttl
podList := &corev1.PodList{}
err = pm.kubeClient.List(ctx, podList, client.InNamespace(pm.namespace), client.MatchingLabels(map[string]string{krmFunctionLabel: podId}))
if err != nil {
klog.Warningf("error when listing pods for %q: %w", image, err)
klog.Warningf("error when listing pods for %q: %v", image, err)
}
if err == nil && len(podList.Items) > 0 {
// TODO: maybe we should randomly pick one that is no being deleted.
Expand Down Expand Up @@ -645,7 +645,7 @@ func patchPodWithUnixTimeAnnotation(cl client.Client, podKey client.ObjectKey, t
pod.Namespace = podKey.Namespace
pod.Name = podKey.Name
if err := cl.Patch(context.Background(), pod, client.RawPatch(types.MergePatchType, patch)); err != nil {
klog.Warningf("unable to patch last-use annotation for pod %v/%v: %w", podKey.Namespace, podKey.Name, err)
klog.Warningf("unable to patch last-use annotation for pod %v/%v: %v", podKey.Namespace, podKey.Name, err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/commands/util/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func UpdateQPS(flags *genericclioptions.ConfigFlags) {

enabled, err := flowcontrol.IsEnabled(ctx, c)
if err != nil {
klog.Warning("Failed to query apiserver to check for flow control enablement: %v", err)
klog.Warningf("Failed to query apiserver to check for flow control enablement: %v", err)
// Default to the lower QPS limits.
}

Expand Down
13 changes: 6 additions & 7 deletions pkg/oci/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/GoogleContainerTools/kpt/pkg/oci"
"github.com/google/go-containerregistry/pkg/v1/mutate"
"github.com/nephio-project/porch/api/porch/v1alpha1"
api "github.com/nephio-project/porch/api/porch/v1alpha1"
"github.com/nephio-project/porch/pkg/repository"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
Expand Down Expand Up @@ -92,7 +91,7 @@ func (r *ociRepository) getRevisionNumber(ctx context.Context, imageRef oci.Imag
return manifest.Annotations[annotationKeyRevision], nil
}

func (r *ociRepository) loadTasks(ctx context.Context, imageRef oci.ImageDigestName) ([]api.Task, error) {
func (r *ociRepository) loadTasks(ctx context.Context, imageRef oci.ImageDigestName) ([]v1alpha1.Task, error) {
ctx, span := tracer.Start(ctx, "ociRepository::loadTasks", trace.WithAttributes(
attribute.Stringer("image", imageRef),
))
Expand All @@ -103,15 +102,15 @@ func (r *ociRepository) loadTasks(ctx context.Context, imageRef oci.ImageDigestN
return nil, fmt.Errorf("error fetching config for image: %w", err)
}

var tasks []api.Task
var tasks []v1alpha1.Task
for i := range configFile.History {
history := &configFile.History[i]
command := history.CreatedBy
if strings.HasPrefix(command, "kpt:") {
task := api.Task{}
task := v1alpha1.Task{}
b := []byte(strings.TrimPrefix(command, "kpt:"))
if err := json.Unmarshal(b, &task); err != nil {
klog.Warningf("failed to unmarshal task command %q: %w", command, err)
klog.Warningf("failed to unmarshal task command %q: %v", command, err)
continue
}
tasks = append(tasks, task)
Expand Down Expand Up @@ -180,14 +179,14 @@ func LoadResources(ctx context.Context, s *oci.Storage, imageName *oci.ImageDige
tarReader := tar.NewReader(f)

// TODO: Check hash here? Or otherwise handle error?
resources, err := loadResourcesFromTar(ctx, tarReader)
resources, err := loadResourcesFromTar(tarReader)
if err != nil {
return nil, err
}
return resources, nil
}

func loadResourcesFromTar(ctx context.Context, tarReader *tar.Reader) (*repository.PackageResources, error) {
func loadResourcesFromTar(tarReader *tar.Reader) (*repository.PackageResources, error) {
resources := &repository.PackageResources{
Contents: map[string]string{},
}
Expand Down
17 changes: 8 additions & 9 deletions pkg/oci/mutate.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ import (
"github.com/google/go-containerregistry/pkg/v1/remote"
"github.com/google/go-containerregistry/pkg/v1/stream"
"github.com/nephio-project/porch/api/porch/v1alpha1"
api "github.com/nephio-project/porch/api/porch/v1alpha1"
"github.com/nephio-project/porch/pkg/repository"
"go.opentelemetry.io/otel/trace"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
)

func (r *ociRepository) CreatePackageRevision(ctx context.Context, obj *api.PackageRevision) (repository.PackageDraft, error) {
func (r *ociRepository) CreatePackageRevision(ctx context.Context, obj *v1alpha1.PackageRevision) (repository.PackageDraft, error) {
base := empty.Image

packageName := obj.Spec.PackageName
Expand All @@ -59,7 +58,7 @@ func (r *ociRepository) CreatePackageRevision(ctx context.Context, obj *api.Pack
return &ociPackageDraft{
packageName: packageName,
parent: r,
tasks: []api.Task{},
tasks: []v1alpha1.Task{},
base: base,
tag: ociRepo.Tag(string(obj.Spec.WorkspaceName)),
lifecycle: v1alpha1.PackageRevisionLifecycleDraft,
Expand Down Expand Up @@ -96,7 +95,7 @@ func (r *ociRepository) UpdatePackageRevision(ctx context.Context, old repositor
return &ociPackageDraft{
packageName: packageName,
parent: r,
tasks: []api.Task{},
tasks: []v1alpha1.Task{},
base: base,
tag: ref,
lifecycle: oldPackage.Lifecycle(),
Expand All @@ -110,7 +109,7 @@ type ociPackageDraft struct {

parent *ociRepository

tasks []api.Task
tasks []v1alpha1.Task

base v1.Image
tag name.Tag
Expand All @@ -121,8 +120,8 @@ type ociPackageDraft struct {

var _ repository.PackageDraft = (*ociPackageDraft)(nil)

func (p *ociPackageDraft) UpdateResources(ctx context.Context, new *api.PackageRevisionResources, task *api.Task) error {
ctx, span := tracer.Start(ctx, "ociPackageDraft::UpdateResources", trace.WithAttributes())
func (p *ociPackageDraft) UpdateResources(ctx context.Context, new *v1alpha1.PackageRevisionResources, task *v1alpha1.Task) error {
_, span := tracer.Start(ctx, "ociPackageDraft::UpdateResources", trace.WithAttributes())
defer span.End()

buf := bytes.NewBuffer(nil)
Expand Down Expand Up @@ -191,7 +190,7 @@ func (p *ociPackageDraft) UpdateResources(ctx context.Context, new *api.PackageR
return nil
}

func (p *ociPackageDraft) UpdateLifecycle(ctx context.Context, new api.PackageRevisionLifecycle) error {
func (p *ociPackageDraft) UpdateLifecycle(ctx context.Context, new v1alpha1.PackageRevisionLifecycle) error {
p.lifecycle = new
return nil
}
Expand Down Expand Up @@ -236,7 +235,7 @@ func (p *ociPackageDraft) Close(ctx context.Context) (repository.PackageRevision
}
var revs []string
for _, rev := range revisions {
if api.LifecycleIsPublished(rev.Lifecycle()) {
if v1alpha1.LifecycleIsPublished(rev.Lifecycle()) {
revs = append(revs, rev.Key().Revision)
}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func (r *ociRepository) ListFunctions(ctx context.Context) ([]repository.Functio
}
meta, err := GetFunctionMeta(repo.Digest(digest).Name(), ctx)
if err != nil {
klog.Warningf(" pull function %v error: %w", functionName, err)
klog.Warningf(" pull function %v error: %v", functionName, err)
continue
}
result = append(result, &ociFunction{
Expand Down Expand Up @@ -520,11 +520,11 @@ func (p *ociPackageRevision) GetKptfile(ctx context.Context) (kptfile.KptFile, e
}

func (p *ociPackageRevision) GetUpstreamLock(context.Context) (kptfile.Upstream, kptfile.UpstreamLock, error) {
return kptfile.Upstream{}, kptfile.UpstreamLock{}, fmt.Errorf("UpstreamLock is not supported for OCI packages (%s)", p.KubeObjectName())
return kptfile.Upstream{}, kptfile.UpstreamLock{}, fmt.Errorf("upstreamLock is not supported for OCI packages (%s)", p.KubeObjectName())
}

func (p *ociPackageRevision) GetLock() (kptfile.Upstream, kptfile.UpstreamLock, error) {
return kptfile.Upstream{}, kptfile.UpstreamLock{}, fmt.Errorf("Lock is not supported for OCI packages (%s)", p.KubeObjectName())
return kptfile.Upstream{}, kptfile.UpstreamLock{}, fmt.Errorf("lock is not supported for oci packages (%s)", p.KubeObjectName())
}

func (p *ociPackageRevision) Lifecycle() v1alpha1.PackageRevisionLifecycle {
Expand Down
5 changes: 3 additions & 2 deletions pkg/registry/porch/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,12 @@ func (r *packages) Create(ctx context.Context, runtimeObject runtime.Object, cre
// 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 (r *packages) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) {
func (r *packages) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc,
updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) {
ctx, span := tracer.Start(ctx, "packages::Update", trace.WithAttributes())
defer span.End()

return r.packageCommon.updatePackage(ctx, name, objInfo, createValidation, updateValidation, forceAllowCreate, options)
return r.packageCommon.updatePackage(ctx, name, objInfo, createValidation, updateValidation, forceAllowCreate)
}

// Delete implements the GracefulDeleter interface.
Expand Down
16 changes: 10 additions & 6 deletions pkg/registry/porch/packagecommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/nephio-project/porch/pkg/engine"
"github.com/nephio-project/porch/pkg/repository"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand All @@ -47,7 +46,8 @@ type packageCommon struct {
createStrategy SimpleRESTCreateStrategy
}

func (r *packageCommon) listPackageRevisions(ctx context.Context, filter packageRevisionFilter, selector labels.Selector, callback func(p *engine.PackageRevision) error) error {
func (r *packageCommon) listPackageRevisions(ctx context.Context, filter packageRevisionFilter,
selector labels.Selector, callback func(p *engine.PackageRevision) error) error {
var opts []client.ListOption
if ns, namespaced := genericapirequest.NamespaceFrom(ctx); namespaced {
opts = append(opts, client.InNamespace(ns))
Expand Down Expand Up @@ -200,7 +200,8 @@ func (r *packageCommon) getPackage(ctx context.Context, name string) (*engine.Pa
}

// Common implementation of PackageRevision update logic.
func (r *packageCommon) updatePackageRevision(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) {
func (r *packageCommon) updatePackageRevision(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo,
createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool) (runtime.Object, bool, error) {
// TODO: Is this all boilerplate??

ns, namespaced := genericapirequest.NamespaceFrom(ctx)
Expand All @@ -221,7 +222,8 @@ func (r *packageCommon) updatePackageRevision(ctx context.Context, name string,
}
}

var oldApiPkgRev runtime.Object // We have to be runtime.Object (and not *api.PackageRevision) or else nil-checks fail (because a nil object is not a nil interface)
// We have to be runtime.Object (and not *api.PackageRevision) or else nil-checks fail (because a nil object is not a nil interface)
var oldApiPkgRev runtime.Object
if !isCreate {
oldApiPkgRev, err = oldRepoPkgRev.GetPackageRevision(ctx)
if err != nil {
Expand Down Expand Up @@ -313,7 +315,8 @@ func (r *packageCommon) updatePackageRevision(ctx context.Context, name string,
}

// Common implementation of Package update logic.
func (r *packageCommon) updatePackage(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) {
func (r *packageCommon) updatePackage(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo,
createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool) (runtime.Object, bool, error) {
// TODO: Is this all boilerplate??

ns, namespaced := genericapirequest.NamespaceFrom(ctx)
Expand All @@ -334,7 +337,8 @@ func (r *packageCommon) updatePackage(ctx context.Context, name string, objInfo
}
}

var oldRuntimeObj runtime.Object // We have to be runtime.Object (and not *api.PackageRevision) or else nil-checks fail (because a nil object is not a nil interface)
// We have to be runtime.Object (and not *api.PackageRevision) or else nil-checks fail (because a nil object is not a nil interface)
var oldRuntimeObj runtime.Object
if !isCreate {
oldRuntimeObj = oldPackage.GetPackage()
}
Expand Down
9 changes: 6 additions & 3 deletions pkg/registry/porch/packagerevision.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ func (r *packageRevisions) Get(ctx context.Context, name string, options *metav1
}

// Create implements the Creater interface.
func (r *packageRevisions) Create(ctx context.Context, runtimeObject runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) {
func (r *packageRevisions) Create(ctx context.Context, runtimeObject runtime.Object, createValidation rest.ValidateObjectFunc,
options *metav1.CreateOptions) (runtime.Object, error) {
ctx, span := tracer.Start(ctx, "packageRevisions::Create", trace.WithAttributes())
defer span.End()

Expand Down Expand Up @@ -183,11 +184,13 @@ func (r *packageRevisions) Create(ctx context.Context, runtimeObject runtime.Obj
// 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 (r *packageRevisions) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) {
func (r *packageRevisions) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc,
updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) {
ctx, span := tracer.Start(ctx, "packageRevisions::Update", trace.WithAttributes())
defer span.End()

return r.packageCommon.updatePackageRevision(ctx, name, objInfo, createValidation, updateValidation, forceAllowCreate, options)
return r.packageCommon.updatePackageRevision(ctx, name, objInfo, createValidation, updateValidation, forceAllowCreate,
)
}

// Delete implements the GracefulDeleter interface.
Expand Down
5 changes: 3 additions & 2 deletions pkg/registry/porch/packagerevisions_approval.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,10 @@ func (a *packageRevisionsApproval) Get(ctx context.Context, name string, 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) {
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) {
allowCreate := false // do not allow create on update
return a.common.updatePackageRevision(ctx, name, objInfo, createValidation, updateValidation, allowCreate, options)
return a.common.updatePackageRevision(ctx, name, objInfo, createValidation, updateValidation, allowCreate)
}

type packageRevisionApprovalStrategy struct{}
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/porch/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (c tableConvertor) ConvertToTable(ctx context.Context, object runtime.Objec

fn := func(obj runtime.Object) error {
cells := c.cells(obj)
if cells == nil || len(cells) == 0 {
if len(cells) == 0 {
return newResourceNotAcceptableError(ctx, c.resource)
}
table.Rows = append(table.Rows, metav1.TableRow{
Expand Down

0 comments on commit 0e92b10

Please sign in to comment.