Skip to content

Commit 59ebc21

Browse files
authored
Merge pull request #28 from coroot/remote_coroot
support `remoteCoroot` in project definition
2 parents 8943cc1 + 01316d9 commit 59ebc21

4 files changed

Lines changed: 111 additions & 8 deletions

File tree

api/v1/config.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,16 @@ type OpenAICompatibleSpec struct {
7272
Model string `json:"model"`
7373
}
7474

75-
// +kubebuilder:validation:XValidation:rule="has(self.memberProjects) && size(self.memberProjects) > 0 ? !has(self.apiKeys) || size(self.apiKeys) == 0 : has(self.apiKeys) && size(self.apiKeys) > 0",message="Exactly one of memberProjects or apiKeys must be non-empty."
75+
// +kubebuilder:validation:XValidation:rule="(has(self.memberProjects) && size(self.memberProjects) > 0 ? 1 : 0) + (has(self.remoteCoroot) ? 1 : 0) + (has(self.apiKeys) && size(self.apiKeys) > 0 ? 1 : 0) == 1",message="Exactly one of memberProjects, remoteCoroot, or apiKeys must be set."
7676
type ProjectSpec struct {
7777
// Project name (e.g., production, staging; required).
7878
// +kubebuilder:validation:Required
7979
Name string `json:"name,omitempty"`
8080
// Names of existing projects to aggregate (multi-cluster mode).
8181
MemberProjects []string `json:"memberProjects,omitempty"`
82-
// Project API keys, used by agents to send telemetry data (required unless memberProjects is set).
82+
// Use another Coroot instance as the data source for this project.
83+
RemoteCoroot *RemoteCorootSpec `json:"remoteCoroot,omitempty"`
84+
// Project API keys, used by agents to send telemetry data (required unless memberProjects or remoteCoroot is set).
8385
ApiKeys []ApiKeySpec `json:"apiKeys,omitempty"`
8486
// Notification integrations.
8587
NotificationIntegrations *NotificationIntegrationsSpec `json:"notificationIntegrations,omitempty"`
@@ -100,6 +102,21 @@ type ApiKeySpec struct {
100102
Description string `json:"description,omitempty"`
101103
}
102104

105+
type RemoteCorootSpec struct {
106+
// Base URL of the remote Coroot instance.
107+
// +kubebuilder:validation:Pattern="^https?://.+$"
108+
Url string `json:"url,omitempty"`
109+
// Whether to skip verification of the Coroot server's TLS certificate.
110+
TlsSkipVerify bool `json:"tlsSkipVerify,omitempty"`
111+
// API key of the remote project.
112+
ApiKey string `json:"apiKey,omitempty"`
113+
// Secret containing the API key.
114+
ApiKeySecret *corev1.SecretKeySelector `json:"apiKeySecret,omitempty"`
115+
// Prometheus query resolution/refresh interval (e.g. 15s).
116+
// +kubebuilder:validation:Pattern="^[0-9]+[smhdwy]$"
117+
MetricResolution string `json:"metricResolution,omitempty"`
118+
}
119+
103120
type NotificationIntegrationsSpec struct {
104121
// The URL of Coroot instance (required). Used for generating links in notifications.
105122
// +kubebuilder:validation:Pattern="^https?://.+$"

api/v1/zz_generated.deepcopy.go

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/coroot.com_coroots.yaml

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6418,7 +6418,7 @@ spec:
64186418
properties:
64196419
apiKeys:
64206420
description: Project API keys, used by agents to send telemetry
6421-
data (required unless memberProjects is set).
6421+
data (required unless memberProjects or remoteCoroot is set).
64226422
items:
64236423
properties:
64246424
description:
@@ -6854,14 +6854,60 @@ spec:
68546854
required:
68556855
- baseURL
68566856
type: object
6857+
remoteCoroot:
6858+
description: Use another Coroot instance as the data source
6859+
for this project.
6860+
properties:
6861+
apiKey:
6862+
description: API key of the remote project.
6863+
type: string
6864+
apiKeySecret:
6865+
description: Secret containing the API key.
6866+
properties:
6867+
key:
6868+
description: The key of the secret to select from. Must
6869+
be a valid secret key.
6870+
type: string
6871+
name:
6872+
default: ""
6873+
description: |-
6874+
Name of the referent.
6875+
This field is effectively required, but due to backwards compatibility is
6876+
allowed to be empty. Instances of this type with an empty value here are
6877+
almost certainly wrong.
6878+
More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
6879+
type: string
6880+
optional:
6881+
description: Specify whether the Secret or its key must
6882+
be defined
6883+
type: boolean
6884+
required:
6885+
- key
6886+
type: object
6887+
x-kubernetes-map-type: atomic
6888+
metricResolution:
6889+
description: Prometheus query resolution/refresh interval
6890+
(e.g. 15s).
6891+
pattern: ^[0-9]+[smhdwy]$
6892+
type: string
6893+
tlsSkipVerify:
6894+
description: Whether to skip verification of the Coroot
6895+
server's TLS certificate.
6896+
type: boolean
6897+
url:
6898+
description: Base URL of the remote Coroot instance.
6899+
pattern: ^https?://.+$
6900+
type: string
6901+
type: object
68576902
required:
68586903
- name
68596904
type: object
68606905
x-kubernetes-validations:
6861-
- message: Exactly one of memberProjects or apiKeys must be non-empty.
6862-
rule: 'has(self.memberProjects) && size(self.memberProjects) >
6863-
0 ? !has(self.apiKeys) || size(self.apiKeys) == 0 : has(self.apiKeys)
6864-
&& size(self.apiKeys) > 0'
6906+
- message: Exactly one of memberProjects, remoteCoroot, or apiKeys
6907+
must be set.
6908+
rule: '(has(self.memberProjects) && size(self.memberProjects)
6909+
> 0 ? 1 : 0) + (has(self.remoteCoroot) ? 1 : 0) + (has(self.apiKeys)
6910+
&& size(self.apiKeys) > 0 ? 1 : 0) == 1'
68656911
type: array
68666912
prometheus:
68676913
description: Prometheus configuration.

controller/coroot.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,22 @@ func (r *CorootReconciler) validateCoroot(ctx context.Context, cr *corootv1.Coro
8282
}
8383

8484
apiKeySecrets := map[string][]string{}
85-
for _, p := range cr.Spec.Projects {
85+
for i := range cr.Spec.Projects {
86+
p := &cr.Spec.Projects[i]
87+
if rc := p.RemoteCoroot; rc != nil {
88+
if rc.ApiKeySecret != nil {
89+
if _, err = r.GetSecret(ctx, cr, rc.ApiKeySecret); err != nil {
90+
logErr("Failed to get Remote Coroot API Key: %s", err.Error())
91+
} else {
92+
rc.ApiKey = configEnvs.Add(rc.ApiKeySecret)
93+
}
94+
rc.ApiKeySecret = nil
95+
}
96+
if rc.Url == "" || rc.ApiKey == "" || rc.MetricResolution == "" {
97+
logErr("Remote Coroot requires url, apiKey, and metricResolution.")
98+
p.RemoteCoroot = nil
99+
}
100+
}
86101
for i, k := range p.ApiKeys {
87102
if k.KeySecret != nil {
88103
apiKeySecrets[k.KeySecret.Name] = append(apiKeySecrets[k.KeySecret.Name], k.KeySecret.Key)

0 commit comments

Comments
 (0)