|
| 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 | + // UpdateStrategy defines how updated catalog source images can be discovered |
| 51 | + // Consists of an interval that defines polling duration and an embedded strategy type |
| 52 | + // +Optional |
| 53 | + UpdateStrategy *UpdateStrategy |
| 54 | + |
| 55 | + // Secrets represent set of secrets that can be used to access the contents of the catalog. |
| 56 | + // It is best to keep this list small, since each will need to be tried for every catalog entry. |
| 57 | + // +Optional |
| 58 | + Secrets []string |
| 59 | + |
| 60 | + // Metadata |
| 61 | + DisplayName string |
| 62 | + Description string |
| 63 | + Publisher string |
| 64 | + Icon Icon |
| 65 | +} |
| 66 | + |
| 67 | +// UpdateStrategy holds all the different types of catalog source update strategies |
| 68 | +// Currently only registry polling strategy is implemented |
| 69 | +type UpdateStrategy struct { |
| 70 | + *RegistryPoll |
| 71 | +} |
| 72 | + |
| 73 | +type RegistryPoll struct { |
| 74 | + // Interval is used to determine the time interval between checks of the latest catalog source version. |
| 75 | + // The catalog operator polls to see if a new version of the catalog source is available. |
| 76 | + // If available, the latest image is pulled and gRPC traffic is directed to the latest catalog source. |
| 77 | + Interval *metav1.Duration |
| 78 | +} |
| 79 | + |
| 80 | +type RegistryServiceStatus struct { |
| 81 | + Protocol string |
| 82 | + ServiceName string |
| 83 | + ServiceNamespace string |
| 84 | + Port string |
| 85 | + CreatedAt metav1.Time |
| 86 | +} |
| 87 | + |
| 88 | +type GRPCConnectionState struct { |
| 89 | + Address string |
| 90 | + LastObservedState string |
| 91 | + LastConnectTime metav1.Time |
| 92 | +} |
| 93 | + |
| 94 | +func (s *RegistryServiceStatus) Address() string { |
| 95 | + return fmt.Sprintf("%s.%s.svc:%s", s.ServiceName, s.ServiceNamespace, s.Port) |
| 96 | +} |
| 97 | + |
| 98 | +type CatalogSourceStatus struct { |
| 99 | + Message string `json:"message,omitempty"` |
| 100 | + Reason ConditionReason `json:"reason,omitempty"` |
| 101 | + ConfigMapResource *ConfigMapResourceReference |
| 102 | + RegistryServiceStatus *RegistryServiceStatus |
| 103 | + GRPCConnectionState *GRPCConnectionState |
| 104 | + LatestImageRegistryPoll *metav1.Time |
| 105 | +} |
| 106 | + |
| 107 | +type ConfigMapResourceReference struct { |
| 108 | + Name string |
| 109 | + Namespace string |
| 110 | + UID types.UID |
| 111 | + ResourceVersion string |
| 112 | + LastUpdateTime metav1.Time |
| 113 | +} |
| 114 | + |
| 115 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 116 | +// +genclient |
| 117 | + |
| 118 | +// CatalogSource is a repository of CSVs, CRDs, and operator packages. |
| 119 | +type CatalogSource struct { |
| 120 | + metav1.TypeMeta |
| 121 | + metav1.ObjectMeta |
| 122 | + |
| 123 | + Spec CatalogSourceSpec |
| 124 | + Status CatalogSourceStatus |
| 125 | +} |
| 126 | + |
| 127 | +func (c *CatalogSource) Address() string { |
| 128 | + if c.Spec.Address != "" { |
| 129 | + return c.Spec.Address |
| 130 | + } |
| 131 | + return c.Status.RegistryServiceStatus.Address() |
| 132 | +} |
| 133 | + |
| 134 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 135 | + |
| 136 | +// CatalogSourceList is a list of CatalogSource resources. |
| 137 | +type CatalogSourceList struct { |
| 138 | + metav1.TypeMeta |
| 139 | + metav1.ListMeta |
| 140 | + |
| 141 | + Items []CatalogSource |
| 142 | +} |
0 commit comments