Skip to content

Commit 681f00b

Browse files
committed
refactor(types): add internal types for olm resources
- Add internal types for OLM resources - Move reference func to its own package - Add missing comments - Clean up scheme registration
1 parent 41821c7 commit 681f00b

21 files changed

+1163
-56
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package operators
2+
3+
import (
4+
"fmt"
5+
6+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
7+
"k8s.io/apimachinery/pkg/types"
8+
)
9+
10+
// CatalogSourceKind is the PascalCase name of a CatalogSource's kind.
11+
const CatalogSourceKind = "CatalogSource"
12+
13+
// SourceType indicates the type of backing store for a CatalogSource
14+
type SourceType string
15+
16+
const (
17+
// SourceTypeInternal (deprecated) specifies a CatalogSource of type SourceTypeConfigmap
18+
SourceTypeInternal SourceType = "internal"
19+
20+
// SourceTypeConfigmap specifies a CatalogSource that generates a configmap-server registry
21+
SourceTypeConfigmap SourceType = "configmap"
22+
23+
// SourceTypeGrpc specifies a CatalogSource that can use an operator registry image to generate a
24+
// registry-server or connect to a pre-existing registry at an address.
25+
SourceTypeGrpc SourceType = "grpc"
26+
)
27+
28+
type CatalogSourceSpec struct {
29+
// SourceType is the type of source
30+
SourceType SourceType
31+
32+
// ConfigMap is the name of the ConfigMap to be used to back a configmap-server registry.
33+
// Only used when SourceType = SourceTypeConfigmap or SourceTypeInternal.
34+
// +Optional
35+
ConfigMap string
36+
37+
// Address is a host that OLM can use to connect to a pre-existing registry.
38+
// Format: <registry-host or ip>:<port>
39+
// Only used when SourceType = SourceTypeGrpc.
40+
// Ignored when the Image field is set.
41+
// +Optional
42+
Address string
43+
44+
// Image is an operator-registry container image to instantiate a registry-server with.
45+
// Only used when SourceType = SourceTypeGrpc.
46+
// If present, the address field is ignored.
47+
// +Optional
48+
Image string
49+
50+
// Secrets represent set of secrets that can be used to access the contents of the catalog.
51+
// It is best to keep this list small, since each will need to be tried for every catalog entry.
52+
// +Optional
53+
Secrets []string
54+
55+
// Metadata
56+
DisplayName string
57+
Description string
58+
Publisher string
59+
Icon Icon
60+
}
61+
62+
type RegistryServiceStatus struct {
63+
Protocol string
64+
ServiceName string
65+
ServiceNamespace string
66+
Port string
67+
CreatedAt metav1.Time
68+
}
69+
70+
func (s *RegistryServiceStatus) Address() string {
71+
return fmt.Sprintf("%s.%s.svc.cluster.local:%s", s.ServiceName, s.ServiceNamespace, s.Port)
72+
}
73+
74+
type CatalogSourceStatus struct {
75+
ConfigMapResource *ConfigMapResourceReference
76+
RegistryServiceStatus *RegistryServiceStatus
77+
LastSync metav1.Time
78+
}
79+
80+
type ConfigMapResourceReference struct {
81+
Name string
82+
Namespace string
83+
84+
UID types.UID
85+
ResourceVersion string
86+
}
87+
88+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
89+
// +genclient
90+
91+
// CatalogSource is a repository of CSVs, CRDs, and operator packages.
92+
type CatalogSource struct {
93+
metav1.TypeMeta
94+
metav1.ObjectMeta
95+
96+
Spec CatalogSourceSpec
97+
Status CatalogSourceStatus
98+
}
99+
100+
func (c *CatalogSource) Address() string {
101+
if c.Spec.Address != "" {
102+
return c.Spec.Address
103+
}
104+
return c.Status.RegistryServiceStatus.Address()
105+
}
106+
107+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
108+
109+
// CatalogSourceList is a list of CatalogSource resources.
110+
type CatalogSourceList struct {
111+
metav1.TypeMeta
112+
metav1.ListMeta
113+
114+
Items []CatalogSource
115+
}

0 commit comments

Comments
 (0)