|
| 1 | +/* |
| 2 | +Copyright 2025. |
| 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 v1alpha1 |
| 18 | + |
| 19 | +import ( |
| 20 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | +) |
| 22 | + |
| 23 | +// +kubebuilder:object:root=true |
| 24 | +// +kubebuilder:resource:scope=Cluster,shortName={pkgsrc,pkgsrcs} |
| 25 | +// +kubebuilder:subresource:status |
| 26 | +// +kubebuilder:printcolumn:name="Variants",type="string",JSONPath=".status.variants",description="Package variants (comma-separated)" |
| 27 | +// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status",description="Ready status" |
| 28 | +// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].message",description="Ready message" |
| 29 | + |
| 30 | +// PackageSource is the Schema for the packagesources API |
| 31 | +type PackageSource struct { |
| 32 | + metav1.TypeMeta `json:",inline"` |
| 33 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 34 | + |
| 35 | + Spec PackageSourceSpec `json:"spec,omitempty"` |
| 36 | + Status PackageSourceStatus `json:"status,omitempty"` |
| 37 | +} |
| 38 | + |
| 39 | +// +kubebuilder:object:root=true |
| 40 | + |
| 41 | +// PackageSourceList contains a list of PackageSources |
| 42 | +type PackageSourceList struct { |
| 43 | + metav1.TypeMeta `json:",inline"` |
| 44 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 45 | + Items []PackageSource `json:"items"` |
| 46 | +} |
| 47 | + |
| 48 | +func init() { |
| 49 | + SchemeBuilder.Register(&PackageSource{}, &PackageSourceList{}) |
| 50 | +} |
| 51 | + |
| 52 | +// PackageSourceSpec defines the desired state of PackageSource |
| 53 | +type PackageSourceSpec struct { |
| 54 | + // SourceRef is the source reference for the package source charts |
| 55 | + // +optional |
| 56 | + SourceRef *PackageSourceRef `json:"sourceRef,omitempty"` |
| 57 | + |
| 58 | + // Variants is a list of package source variants |
| 59 | + // Each variant defines components, applications, dependencies, and libraries for a specific configuration |
| 60 | + // +optional |
| 61 | + Variants []Variant `json:"variants,omitempty"` |
| 62 | +} |
| 63 | + |
| 64 | +// Variant defines a single variant configuration |
| 65 | +type Variant struct { |
| 66 | + // Name is the unique identifier for this variant |
| 67 | + // +required |
| 68 | + Name string `json:"name"` |
| 69 | + |
| 70 | + // DependsOn is a list of package source dependencies |
| 71 | + // For example: "cozystack.networking" |
| 72 | + // +optional |
| 73 | + DependsOn []string `json:"dependsOn,omitempty"` |
| 74 | + |
| 75 | + // Libraries is a list of Helm library charts used by components in this variant |
| 76 | + // +optional |
| 77 | + Libraries []Library `json:"libraries,omitempty"` |
| 78 | + |
| 79 | + // Components is a list of Helm releases to be installed as part of this variant |
| 80 | + // +optional |
| 81 | + Components []Component `json:"components,omitempty"` |
| 82 | +} |
| 83 | + |
| 84 | +// Library defines a Helm library chart |
| 85 | +type Library struct { |
| 86 | + // Name is the optional name for library placed in charts |
| 87 | + // +optional |
| 88 | + Name string `json:"name,omitempty"` |
| 89 | + |
| 90 | + // Path is the path to the library chart directory |
| 91 | + // +required |
| 92 | + Path string `json:"path"` |
| 93 | +} |
| 94 | + |
| 95 | +// PackageSourceRef defines the source reference for package source charts |
| 96 | +type PackageSourceRef struct { |
| 97 | + // Kind of the source reference |
| 98 | + // +kubebuilder:validation:Enum=GitRepository;OCIRepository |
| 99 | + // +required |
| 100 | + Kind string `json:"kind"` |
| 101 | + |
| 102 | + // Name of the source reference |
| 103 | + // +required |
| 104 | + Name string `json:"name"` |
| 105 | + |
| 106 | + // Namespace of the source reference |
| 107 | + // +required |
| 108 | + Namespace string `json:"namespace"` |
| 109 | + |
| 110 | + // Path is the base path where packages are located in the source. |
| 111 | + // For GitRepository, defaults to "packages" if not specified. |
| 112 | + // For OCIRepository, defaults to empty string (root) if not specified. |
| 113 | + // +optional |
| 114 | + Path string `json:"path,omitempty"` |
| 115 | +} |
| 116 | + |
| 117 | +// ComponentInstall defines installation parameters for a component |
| 118 | +type ComponentInstall struct { |
| 119 | + // ReleaseName is the name of the HelmRelease resource that will be created |
| 120 | + // If not specified, defaults to the component Name field |
| 121 | + // +optional |
| 122 | + ReleaseName string `json:"releaseName,omitempty"` |
| 123 | + |
| 124 | + // Namespace is the Kubernetes namespace where the release will be installed |
| 125 | + // +optional |
| 126 | + Namespace string `json:"namespace,omitempty"` |
| 127 | + |
| 128 | + // Privileged indicates whether this release requires privileged access |
| 129 | + // +optional |
| 130 | + Privileged bool `json:"privileged,omitempty"` |
| 131 | + |
| 132 | + // DependsOn is a list of component names that must be installed before this component |
| 133 | + // +optional |
| 134 | + DependsOn []string `json:"dependsOn,omitempty"` |
| 135 | +} |
| 136 | + |
| 137 | +// Component defines a single Helm release component within a package source |
| 138 | +type Component struct { |
| 139 | + // Name is the unique identifier for this component within the package source |
| 140 | + // +required |
| 141 | + Name string `json:"name"` |
| 142 | + |
| 143 | + // Path is the path to the Helm chart directory |
| 144 | + // +required |
| 145 | + Path string `json:"path"` |
| 146 | + |
| 147 | + // Install defines installation parameters for this component |
| 148 | + // +optional |
| 149 | + Install *ComponentInstall `json:"install,omitempty"` |
| 150 | + |
| 151 | + // Libraries is a list of library names that this component depends on |
| 152 | + // These libraries must be defined at the variant level |
| 153 | + // +optional |
| 154 | + Libraries []string `json:"libraries,omitempty"` |
| 155 | + |
| 156 | + // ValuesFiles is a list of values file names to use |
| 157 | + // +optional |
| 158 | + ValuesFiles []string `json:"valuesFiles,omitempty"` |
| 159 | +} |
| 160 | + |
| 161 | +// PackageSourceStatus defines the observed state of PackageSource |
| 162 | +type PackageSourceStatus struct { |
| 163 | + // Variants is a comma-separated list of package variant names |
| 164 | + // This field is populated by the controller based on spec.variants keys |
| 165 | + // +optional |
| 166 | + Variants string `json:"variants,omitempty"` |
| 167 | + |
| 168 | + // Conditions represents the latest available observations of a PackageSource's state |
| 169 | + // +optional |
| 170 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 171 | +} |
0 commit comments