-
Notifications
You must be signed in to change notification settings - Fork 225
/
repository.go
99 lines (82 loc) · 3.75 KB
/
repository.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
// 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 repository
import (
"context"
kptfile "github.com/GoogleContainerTools/kpt/pkg/api/kptfile/v1"
"github.com/GoogleContainerTools/kpt/porch/api/porch/v1alpha1"
)
// TODO: "sigs.k8s.io/kustomize/kyaml/filesys" FileSystem?
type PackageResources struct {
Contents map[string]string
}
// PackageRevision is an abstract package version.
// We have a single object for both Revision and Resources, because conceptually they are one object.
// The best way we've found (so far) to represent them in k8s is as two resources, but they map to the same object.
// Interesting reading: https://github.com/zecke/Kubernetes/blob/master/docs/devel/api-conventions.md#differing-representations
type PackageRevision interface {
Name() string
GetPackageRevision() (*v1alpha1.PackageRevision, error)
// TODO: return PackageResources or filesystem abstraction?
GetResources(ctx context.Context) (*v1alpha1.PackageRevisionResources, error)
GetUpstreamLock() (kptfile.Upstream, kptfile.UpstreamLock, error)
}
type PackageDraft interface {
UpdateResources(ctx context.Context, new *v1alpha1.PackageRevisionResources, task *v1alpha1.Task) error
// Updates desired lifecycle of the package. The lifecycle is applied on Close.
UpdateLifecycle(ctx context.Context, new v1alpha1.PackageRevisionLifecycle) error
// Finish round of updates.
Close(ctx context.Context) (PackageRevision, error)
}
// Function is an abstract function.
type Function interface {
Name() string
GetFunction() (*v1alpha1.Function, error)
}
// Repository is the interface for interacting with packages in repositories
// TODO: we may need interface to manage repositories too. Stay tuned.
type Repository interface {
ListPackageRevisions(ctx context.Context) ([]PackageRevision, error)
// CreatePackageRevision creates a new package revision
CreatePackageRevision(ctx context.Context, obj *v1alpha1.PackageRevision) (PackageDraft, error)
// DeletePackageRevision deletes a package revision
DeletePackageRevision(ctx context.Context, old PackageRevision) error
// UpdatePackage updates a package
UpdatePackage(ctx context.Context, old PackageRevision) (PackageDraft, error)
}
type FunctionRepository interface {
// TODO: Should repository understand functions, or just packages (and function is just a package in an OCI repo?)
ListFunctions(ctx context.Context) ([]Function, error)
}
// The definitions below would be more appropriately located in a package usable by any Porch component.
// They are located in repository package because repository is one such package though thematically
// they rather belong to a package of their own.
type Credential struct {
// TODO: support different credential types
Data map[string][]byte
}
type CredentialResolver interface {
ResolveCredential(ctx context.Context, namespace, name string) (Credential, error)
}
type UserInfo struct {
Name string
Email string
}
// UserInfoProvider providers name of the authenticated user on whose behalf the request
// is being processed.
type UserInfoProvider interface {
// GetUserInfo returns the information about the user on whose behalf the request is being
// processed, if any. If user cannot be determnined, returns nil.
GetUserInfo(ctx context.Context) *UserInfo
}