Skip to content

Commit 227848a

Browse files
authored
Introduce cozystack-controller (#560)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit Based on the comprehensive summary of changes, here are the release notes: - **New Features** - Added a new Kubernetes controller for managing workload monitoring - Introduced telemetry collection capabilities with configurable options - Added new Custom Resource Definitions (CRDs) for Workload and WorkloadMonitor - **Improvements** - Enhanced API infrastructure with new API group and version - Improved deployment configurations for various system components - Added development container and workflow configurations - **Bug Fixes** - Updated import paths to correct domain naming - **Chores** - Updated copyright years - Refined module dependencies - Standardized code linting and testing configurations - **Infrastructure** - Increased `cozystack-api` deployment replicas from 1 to 2 for improved availability <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
1 parent 7cfb90d commit 227848a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1789
-57
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ test:
3737
make -C packages/core/testing apply
3838
make -C packages/core/testing test
3939
make -C packages/core/testing test-applications
40+
41+
generate:
42+
hack/update-codegen.sh

api/api-rules/cozystack_api_violation_exceptions.list

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
API rule violation: list_type_missing,github.com/aenix.io/cozystack/pkg/apis/apps/v1alpha1,ApplicationStatus,Conditions
1+
API rule violation: list_type_missing,github.com/aenix-io/cozystack/pkg/apis/apps/v1alpha1,ApplicationStatus,Conditions
22
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1,JSONSchemaProps,Ref
33
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1,JSONSchemaProps,Schema
44
API rule violation: names_match,k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1,JSONSchemaProps,XEmbeddedResource

api/v1alpha1/groupversion_info.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 contains API Schema definitions for the v1alpha1 API group.
18+
// +kubebuilder:object:generate=true
19+
// +groupName=cozystack.io
20+
package v1alpha1
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects.
29+
GroupVersion = schema.GroupVersion{Group: "cozystack.io", Version: "v1alpha1"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)

api/v1alpha1/workload_types.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
"k8s.io/apimachinery/pkg/api/resource"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
// WorkloadStatus defines the observed state of Workload
25+
type WorkloadStatus struct {
26+
// Kind represents the type of workload (redis, postgres, etc.)
27+
// +required
28+
Kind string `json:"kind"`
29+
30+
// Type represents the specific role of the workload (redis, sentinel, etc.)
31+
// If not specified, defaults to Kind
32+
// +optional
33+
Type string `json:"type,omitempty"`
34+
35+
// Resources specifies the compute resources allocated to this workload
36+
// +required
37+
Resources map[string]resource.Quantity `json:"resources"`
38+
39+
// Operational indicates if all pods of the workload are ready
40+
// +optional
41+
Operational bool `json:"operational"`
42+
}
43+
44+
// +kubebuilder:object:root=true
45+
// +kubebuilder:printcolumn:name="Kind",type="string",JSONPath=".status.kind"
46+
// +kubebuilder:printcolumn:name="Type",type="string",JSONPath=".status.type"
47+
// +kubebuilder:printcolumn:name="CPU",type="string",JSONPath=".status.resources.cpu"
48+
// +kubebuilder:printcolumn:name="Memory",type="string",JSONPath=".status.resources.memory"
49+
// +kubebuilder:printcolumn:name="Operational",type="boolean",JSONPath=`.status.operational`
50+
51+
// Workload is the Schema for the workloads API
52+
type Workload struct {
53+
metav1.TypeMeta `json:",inline"`
54+
metav1.ObjectMeta `json:"metadata,omitempty"`
55+
56+
Status WorkloadStatus `json:"status,omitempty"`
57+
}
58+
59+
// +kubebuilder:object:root=true
60+
61+
// WorkloadList contains a list of Workload
62+
type WorkloadList struct {
63+
metav1.TypeMeta `json:",inline"`
64+
metav1.ListMeta `json:"metadata,omitempty"`
65+
Items []Workload `json:"items"`
66+
}
67+
68+
func init() {
69+
SchemeBuilder.Register(&Workload{}, &WorkloadList{})
70+
}

api/v1alpha1/workloadmonitor_types.go

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package v1alpha1
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
)
6+
7+
// WorkloadMonitorSpec defines the desired state of WorkloadMonitor
8+
type WorkloadMonitorSpec struct {
9+
// Selector is a label selector to find workloads to monitor
10+
// +required
11+
Selector map[string]string `json:"selector"`
12+
13+
// Kind specifies the kind of the workload
14+
// +optional
15+
Kind string `json:"kind,omitempty"`
16+
17+
// Type specifies the type of the workload
18+
// +optional
19+
Type string `json:"type,omitempty"`
20+
21+
// Version specifies the version of the workload
22+
// +optional
23+
Version string `json:"version,omitempty"`
24+
25+
// MinReplicas specifies the minimum number of replicas that should be available
26+
// +kubebuilder:validation:Minimum=0
27+
// +optional
28+
MinReplicas *int32 `json:"minReplicas,omitempty"`
29+
30+
// Replicas is the desired number of replicas
31+
// If not specified, will use observedReplicas as the target
32+
// +kubebuilder:validation:Minimum=0
33+
// +optional
34+
Replicas *int32 `json:"replicas,omitempty"`
35+
}
36+
37+
// WorkloadMonitorStatus defines the observed state of WorkloadMonitor
38+
type WorkloadMonitorStatus struct {
39+
// Operational indicates if the workload meets all operational requirements
40+
// +optional
41+
Operational *bool `json:"operational,omitempty"`
42+
43+
// AvailableReplicas is the number of ready replicas
44+
// +optional
45+
AvailableReplicas int32 `json:"availableReplicas"`
46+
47+
// ObservedReplicas is the total number of pods observed
48+
// +optional
49+
ObservedReplicas int32 `json:"observedReplicas"`
50+
}
51+
52+
// +kubebuilder:object:root=true
53+
// +kubebuilder:subresource:status
54+
// +kubebuilder:printcolumn:name="Kind",type="string",JSONPath=".spec.kind"
55+
// +kubebuilder:printcolumn:name="Type",type="string",JSONPath=".spec.type"
56+
// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.version"
57+
// +kubebuilder:printcolumn:name="Replicas",type="integer",JSONPath=".spec.replicas"
58+
// +kubebuilder:printcolumn:name="MinReplicas",type="integer",JSONPath=".spec.minReplicas"
59+
// +kubebuilder:printcolumn:name="Available",type="integer",JSONPath=".status.availableReplicas"
60+
// +kubebuilder:printcolumn:name="Observed",type="integer",JSONPath=".status.observedReplicas"
61+
// +kubebuilder:printcolumn:name="Operational",type="boolean",JSONPath=".status.operational"
62+
63+
// WorkloadMonitor is the Schema for the workloadmonitors API
64+
type WorkloadMonitor struct {
65+
metav1.TypeMeta `json:",inline"`
66+
metav1.ObjectMeta `json:"metadata,omitempty"`
67+
68+
Spec WorkloadMonitorSpec `json:"spec,omitempty"`
69+
Status WorkloadMonitorStatus `json:"status,omitempty"`
70+
}
71+
72+
// +kubebuilder:object:root=true
73+
74+
// WorkloadMonitorList contains a list of WorkloadMonitor
75+
type WorkloadMonitorList struct {
76+
metav1.TypeMeta `json:",inline"`
77+
metav1.ListMeta `json:"metadata,omitempty"`
78+
Items []WorkloadMonitor `json:"items"`
79+
}
80+
81+
func init() {
82+
SchemeBuilder.Register(&WorkloadMonitor{}, &WorkloadMonitorList{})
83+
}
84+
85+
// GetSelector returns the label selector from metadata
86+
func (w *WorkloadMonitor) GetSelector() map[string]string {
87+
return w.Spec.Selector
88+
}
89+
90+
// Selector specifies the label selector for workloads
91+
type Selector map[string]string

0 commit comments

Comments
 (0)