Skip to content

Commit 42c3363

Browse files
authored
feat: add AgentConfiguration crd (#505)
* add AgentConfiguration crd * refactor * fix tests * linter * add debug * add servicePollInterval * add CRD docs * tune poll * update poller * fix test * disable pipeline gates reconciler by default
1 parent fdc71ba commit 42c3363

31 files changed

+999
-54
lines changed

api/v1alpha1/agentconfig_types.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package v1alpha1
2+
3+
import (
4+
"k8s.io/apimachinery/pkg/api/meta"
5+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
6+
)
7+
8+
// AgentConfigurationSpec defines the desired state of AgentConfiguration
9+
type AgentConfigurationSpec struct {
10+
// ServicePollInterval defines how often the agent polls for services.
11+
// Expected format is a duration string (e.g., "30s", "5m").
12+
// Set to "0s" to disable service polling.
13+
ServicePollInterval *string `json:"servicePollInterval,omitempty"`
14+
15+
// ClusterPingInterval specifies the interval at which the agent pings the cluster.
16+
// Set to "0s" to disable cluster pings.
17+
ClusterPingInterval *string `json:"clusterPingInterval,omitempty"`
18+
19+
// CompatibilityUploadInterval determines how frequently the agent uploads compatibility data.
20+
// Set to "0s" to disable compatibility uploads.
21+
CompatibilityUploadInterval *string `json:"compatibilityUploadInterval,omitempty"`
22+
23+
// StackPollInterval sets how often the agent polls for stack updates or changes.
24+
// Set to "0s" to disable stack polling.
25+
StackPollInterval *string `json:"stackPollInterval,omitempty"`
26+
27+
// PipelineGateInterval specifies how frequently the agent checks pipeline gates.
28+
// Set to "0s" to disable pipeline gate checks.
29+
PipelineGateInterval *string `json:"pipelineGateInterval,omitempty"`
30+
31+
// MaxConcurrentReconciles controls the maximum number of concurrent reconcile loops.
32+
// Higher values can increase throughput at the cost of resource usage.
33+
MaxConcurrentReconciles *int `json:"maxConcurrentReconciles,omitempty"`
34+
35+
// VulnerabilityReportUploadInterval sets how often vulnerability reports are uploaded.
36+
// Set to "0s" to disable vulnerability report uploads.
37+
VulnerabilityReportUploadInterval *string `json:"vulnerabilityReportUploadInterval,omitempty"`
38+
}
39+
40+
//+kubebuilder:object:root=true
41+
//+kubebuilder:subresource:status
42+
// +kubebuilder:resource:scope=Cluster
43+
44+
// AgentConfiguration is the deployment operator configuration
45+
type AgentConfiguration struct {
46+
metav1.TypeMeta `json:",inline"`
47+
metav1.ObjectMeta `json:"metadata,omitempty"`
48+
49+
Spec AgentConfigurationSpec `json:"spec,omitempty"`
50+
Status Status `json:"status,omitempty"`
51+
}
52+
53+
//+kubebuilder:object:root=true
54+
55+
// AgentConfigurationList contains a list of AgentConfiguration
56+
type AgentConfigurationList struct {
57+
metav1.TypeMeta `json:",inline"`
58+
metav1.ListMeta `json:"metadata,omitempty"`
59+
Items []AgentConfiguration `json:"items"`
60+
}
61+
62+
func init() {
63+
SchemeBuilder.Register(&AgentConfiguration{}, &AgentConfigurationList{})
64+
}
65+
66+
func (c *AgentConfiguration) SetCondition(condition metav1.Condition) {
67+
meta.SetStatusCondition(&c.Status.Conditions, condition)
68+
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 109 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.16.3
7+
name: agentconfigurations.deployments.plural.sh
8+
spec:
9+
group: deployments.plural.sh
10+
names:
11+
kind: AgentConfiguration
12+
listKind: AgentConfigurationList
13+
plural: agentconfigurations
14+
singular: agentconfiguration
15+
scope: Cluster
16+
versions:
17+
- name: v1alpha1
18+
schema:
19+
openAPIV3Schema:
20+
description: AgentConfiguration is the deployment operator configuration
21+
properties:
22+
apiVersion:
23+
description: |-
24+
APIVersion defines the versioned schema of this representation of an object.
25+
Servers should convert recognized schemas to the latest internal value, and
26+
may reject unrecognized values.
27+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
28+
type: string
29+
kind:
30+
description: |-
31+
Kind is a string value representing the REST resource this object represents.
32+
Servers may infer this from the endpoint the client submits requests to.
33+
Cannot be updated.
34+
In CamelCase.
35+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
36+
type: string
37+
metadata:
38+
type: object
39+
spec:
40+
description: AgentConfigurationSpec defines the desired state of AgentConfiguration
41+
properties:
42+
clusterPingInterval:
43+
description: |-
44+
ClusterPingInterval specifies the interval at which the agent pings the cluster.
45+
Set to "0s" to disable cluster pings.
46+
type: string
47+
compatibilityUploadInterval:
48+
description: |-
49+
CompatibilityUploadInterval determines how frequently the agent uploads compatibility data.
50+
Set to "0s" to disable compatibility uploads.
51+
type: string
52+
maxConcurrentReconciles:
53+
description: |-
54+
MaxConcurrentReconciles controls the maximum number of concurrent reconcile loops.
55+
Higher values can increase throughput at the cost of resource usage.
56+
type: integer
57+
pipelineGateInterval:
58+
description: |-
59+
PipelineGateInterval specifies how frequently the agent checks pipeline gates.
60+
Set to "0s" to disable pipeline gate checks.
61+
type: string
62+
servicePollInterval:
63+
description: |-
64+
ServicePollInterval defines how often the agent polls for services.
65+
Expected format is a duration string (e.g., "30s", "5m").
66+
Set to "0s" to disable service polling.
67+
type: string
68+
stackPollInterval:
69+
description: |-
70+
StackPollInterval sets how often the agent polls for stack updates or changes.
71+
Set to "0s" to disable stack polling.
72+
type: string
73+
vulnerabilityReportUploadInterval:
74+
description: |-
75+
VulnerabilityReportUploadInterval sets how often vulnerability reports are uploaded.
76+
Set to "0s" to disable vulnerability report uploads.
77+
type: string
78+
type: object
79+
status:
80+
properties:
81+
conditions:
82+
description: Represents the observations of a PrAutomation's current
83+
state.
84+
items:
85+
description: Condition contains details for one aspect of the current
86+
state of this API Resource.
87+
properties:
88+
lastTransitionTime:
89+
description: |-
90+
lastTransitionTime is the last time the condition transitioned from one status to another.
91+
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
92+
format: date-time
93+
type: string
94+
message:
95+
description: |-
96+
message is a human readable message indicating details about the transition.
97+
This may be an empty string.
98+
maxLength: 32768
99+
type: string
100+
observedGeneration:
101+
description: |-
102+
observedGeneration represents the .metadata.generation that the condition was set based upon.
103+
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
104+
with respect to the current state of the instance.
105+
format: int64
106+
minimum: 0
107+
type: integer
108+
reason:
109+
description: |-
110+
reason contains a programmatic identifier indicating the reason for the condition's last transition.
111+
Producers of specific condition types may define expected values and meanings for this field,
112+
and whether the values are considered a guaranteed API.
113+
The value should be a CamelCase string.
114+
This field may not be empty.
115+
maxLength: 1024
116+
minLength: 1
117+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
118+
type: string
119+
status:
120+
description: status of the condition, one of True, False, Unknown.
121+
enum:
122+
- "True"
123+
- "False"
124+
- Unknown
125+
type: string
126+
type:
127+
description: type of condition in CamelCase or in foo.example.com/CamelCase.
128+
maxLength: 316
129+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
130+
type: string
131+
required:
132+
- lastTransitionTime
133+
- message
134+
- reason
135+
- status
136+
- type
137+
type: object
138+
type: array
139+
x-kubernetes-list-map-keys:
140+
- type
141+
x-kubernetes-list-type: map
142+
id:
143+
description: ID of the resource in the Console API.
144+
type: string
145+
sha:
146+
description: SHA of last applied configuration.
147+
type: string
148+
type: object
149+
type: object
150+
served: true
151+
storage: true
152+
subresources:
153+
status: {}

cmd/agent/args/args.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ const (
7373

7474
defaultRuntimeServicePingInterval = "3m"
7575
defaultRuntimeServicePingIntervalDuration = 3 * time.Minute
76+
77+
defaultPipelineGatesPollInterval = "0s"
78+
defaultPipelineGatesPollIntervalDuration = 0 * time.Second
7679
)
7780

7881
var (
@@ -114,6 +117,7 @@ var (
114117
argWorkqueueBurst = flag.Int("workqueue-burst", 50, "The maximum number of items to process at a time.")
115118
argClusterPingInterval = flag.String("cluster-ping-interval", defaultClusterPingInterval, "Time interval to ping cluster.")
116119
argRuntimeServicePingInterval = flag.String("runtime-service-ping-interval", defaultRuntimeServicePingInterval, "Time interval to register runtime services.")
120+
argPipelineGatesPollInterval = flag.String("pipline-gates-poll-interval", defaultPipelineGatesPollInterval, "Time interval to poll PipelineGates resources from the Console API. It's disabled by default.")
117121
serviceSet containers.Set[string]
118122
)
119123

@@ -397,3 +401,13 @@ func RuntimeServicesPingInterval() time.Duration {
397401

398402
return duration
399403
}
404+
405+
func PipelineGatesInterval() time.Duration {
406+
duration, err := time.ParseDuration(*argPipelineGatesPollInterval)
407+
if err != nil {
408+
klog.ErrorS(err, "Could not parse pipline-gates-poll-interval", "value", *argPipelineGatesPollInterval, "default", defaultPipelineGatesPollInterval)
409+
return defaultPipelineGatesPollIntervalDuration
410+
}
411+
412+
return duration
413+
}

0 commit comments

Comments
 (0)