crossplane

Форк
0
142 строки · 4.1 Кб
1
/*
2
Copyright 2021 The Crossplane Authors.
3

4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7

8
    http://www.apache.org/licenses/LICENSE-2.0
9

10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16

17
package v1beta1
18

19
import (
20
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21

22
	"github.com/crossplane/crossplane/internal/dag"
23
)
24

25
var _ dag.Node = &Dependency{}
26
var _ dag.Node = &LockPackage{}
27

28
// A PackageType is a type of package.
29
type PackageType string
30

31
// Types of packages.
32
const (
33
	ConfigurationPackageType PackageType = "Configuration"
34
	ProviderPackageType      PackageType = "Provider"
35
	FunctionPackageType      PackageType = "Function"
36
)
37

38
// LockPackage is a package that is in the lock.
39
type LockPackage struct {
40
	// Name corresponds to the name of the package revision for this package.
41
	Name string `json:"name"`
42

43
	// Type is the type of package. Can be either Configuration or Provider.
44
	Type PackageType `json:"type"`
45

46
	// Source is the OCI image name without a tag or digest.
47
	Source string `json:"source"`
48

49
	// Version is the tag or digest of the OCI image.
50
	Version string `json:"version"`
51

52
	// Dependencies are the list of dependencies of this package. The order of
53
	// the dependencies will dictate the order in which they are resolved.
54
	Dependencies []Dependency `json:"dependencies"`
55
}
56

57
// ToNodes converts LockPackages to DAG nodes.
58
func ToNodes(pkgs ...LockPackage) []dag.Node {
59
	nodes := make([]dag.Node, len(pkgs))
60
	for i, r := range pkgs {
61
		r := r // Pin range variable so we can take its address.
62
		nodes[i] = &r
63
	}
64
	return nodes
65
}
66

67
// Identifier returns the source of a LockPackage.
68
func (l *LockPackage) Identifier() string {
69
	return l.Source
70
}
71

72
// Neighbors returns dependencies of a LockPackage.
73
func (l *LockPackage) Neighbors() []dag.Node {
74
	nodes := make([]dag.Node, len(l.Dependencies))
75
	for i, r := range l.Dependencies {
76
		r := r // Pin range variable so we can take its address.
77
		nodes[i] = &r
78
	}
79
	return nodes
80
}
81

82
// AddNeighbors adds dependencies to a LockPackage. A LockPackage should always
83
// have all dependencies declared before being added to the Lock, so we no-op
84
// when adding a neighbor.
85
func (l *LockPackage) AddNeighbors(_ ...dag.Node) error {
86
	return nil
87
}
88

89
// A Dependency is a dependency of a package in the lock.
90
type Dependency struct {
91
	// Package is the OCI image name without a tag or digest.
92
	Package string `json:"package"`
93

94
	// Type is the type of package. Can be either Configuration or Provider.
95
	Type PackageType `json:"type"`
96

97
	// Constraints is a valid semver range, which will be used to select a valid
98
	// dependency version.
99
	Constraints string `json:"constraints"`
100
}
101

102
// Identifier returns a dependency's source.
103
func (d *Dependency) Identifier() string {
104
	return d.Package
105
}
106

107
// Neighbors in is a no-op for dependencies because we are not yet aware of its
108
// dependencies.
109
func (d *Dependency) Neighbors() []dag.Node {
110
	return nil
111
}
112

113
// AddNeighbors is a no-op for dependencies. We should never be adding neighbors
114
// to a dependency.
115
func (d *Dependency) AddNeighbors(...dag.Node) error {
116
	return nil
117
}
118

119
// +kubebuilder:object:root=true
120
// +genclient
121
// +genclient:nonNamespaced
122

123
// Lock is the CRD type that tracks package dependencies.
124
// +kubebuilder:storageversion
125
// +kubebuilder:subresource:status
126
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
127
// +kubebuilder:resource:scope=Cluster
128
type Lock struct {
129
	metav1.TypeMeta   `json:",inline"`
130
	metav1.ObjectMeta `json:"metadata,omitempty"`
131

132
	Packages []LockPackage `json:"packages,omitempty"`
133
}
134

135
// +kubebuilder:object:root=true
136

137
// LockList contains a list of Lock.
138
type LockList struct {
139
	metav1.TypeMeta `json:",inline"`
140
	metav1.ListMeta `json:"metadata,omitempty"`
141
	Items           []Lock `json:"items"`
142
}
143

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.