Skip to content

Commit 9848810

Browse files
committed
[cozystack-operator] Introduce API objects: packages and packagesources
Signed-off-by: Andrei Kvapil <[email protected]>
1 parent fe7bdcf commit 9848810

9 files changed

Lines changed: 1048 additions & 13 deletions

File tree

‎api/v1alpha1/cozystackresourcedefinitions_types.go‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ type CozystackResourceDefinitionApplication struct {
9292

9393
type CozystackResourceDefinitionRelease struct {
9494
// Helm chart configuration
95-
Chart CozystackResourceDefinitionChart `json:"chart"`
95+
// +optional
96+
Chart CozystackResourceDefinitionChart `json:"chart,omitempty"`
9697
// Labels for the release
9798
Labels map[string]string `json:"labels,omitempty"`
9899
// Prefix for the release name
@@ -110,17 +111,18 @@ type CozystackResourceDefinitionRelease struct {
110111
// - {{ .namespace }}: The namespace of the resource being processed
111112
//
112113
// Example YAML:
113-
// secrets:
114-
// include:
115-
// - matchExpressions:
116-
// - key: badlabel
117-
// operator: DoesNotExist
118-
// matchLabels:
119-
// goodlabel: goodvalue
120-
// resourceNames:
121-
// - "{{ .name }}-secret"
122-
// - "{{ .kind }}-{{ .name }}-tls"
123-
// - "specificname"
114+
//
115+
// secrets:
116+
// include:
117+
// - matchExpressions:
118+
// - key: badlabel
119+
// operator: DoesNotExist
120+
// matchLabels:
121+
// goodlabel: goodvalue
122+
// resourceNames:
123+
// - "{{ .name }}-secret"
124+
// - "{{ .kind }}-{{ .name }}-tls"
125+
// - "specificname"
124126
type CozystackResourceDefinitionResourceSelector struct {
125127
metav1.LabelSelector `json:",inline"`
126128
// ResourceNames is a list of resource names to match

‎api/v1alpha1/package_types.go‎

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
// +kubebuilder:object:root=true
25+
// +kubebuilder:resource:scope=Cluster,shortName={pkg,pkgs}
26+
// +kubebuilder:subresource:status
27+
// +kubebuilder:printcolumn:name="Variant",type="string",JSONPath=".spec.variant",description="Selected variant"
28+
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status",description="Ready status"
29+
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].message",description="Ready message"
30+
31+
// Package is the Schema for the packages API
32+
type Package struct {
33+
metav1.TypeMeta `json:",inline"`
34+
metav1.ObjectMeta `json:"metadata,omitempty"`
35+
36+
Spec PackageSpec `json:"spec,omitempty"`
37+
Status PackageStatus `json:"status,omitempty"`
38+
}
39+
40+
// +kubebuilder:object:root=true
41+
42+
// PackageList contains a list of Packages
43+
type PackageList struct {
44+
metav1.TypeMeta `json:",inline"`
45+
metav1.ListMeta `json:"metadata,omitempty"`
46+
Items []Package `json:"items"`
47+
}
48+
49+
func init() {
50+
SchemeBuilder.Register(&Package{}, &PackageList{})
51+
}
52+
53+
// PackageSpec defines the desired state of Package
54+
type PackageSpec struct {
55+
// Variant is the name of the variant to use from the PackageSource
56+
// If not specified, defaults to "default"
57+
// +optional
58+
Variant string `json:"variant,omitempty"`
59+
60+
// IgnoreDependencies is a list of package source dependencies to ignore
61+
// Dependencies listed here will not be installed even if they are specified in the PackageSource
62+
// +optional
63+
IgnoreDependencies []string `json:"ignoreDependencies,omitempty"`
64+
65+
// Components is a map of release name to component overrides
66+
// Allows overriding values and enabling/disabling specific components from the PackageSource
67+
// +optional
68+
Components map[string]PackageComponent `json:"components,omitempty"`
69+
}
70+
71+
// PackageComponent defines overrides for a specific component
72+
type PackageComponent struct {
73+
// Enabled indicates whether this component should be installed
74+
// If false, the component will be disabled even if it's defined in the PackageSource
75+
// +optional
76+
Enabled *bool `json:"enabled,omitempty"`
77+
78+
// Values contains Helm chart values as a JSON object
79+
// These values will be merged with the default values from the PackageSource
80+
// +optional
81+
Values *apiextensionsv1.JSON `json:"values,omitempty"`
82+
}
83+
84+
// PackageStatus defines the observed state of Package
85+
type PackageStatus struct {
86+
// Conditions represents the latest available observations of a Package's state
87+
// +optional
88+
Conditions []metav1.Condition `json:"conditions,omitempty"`
89+
}
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
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

Comments
 (0)