Skip to content

Commit d75664d

Browse files
committed
Add archive logs target CRD
1 parent 8c27675 commit d75664d

File tree

19 files changed

+2936
-4
lines changed

19 files changed

+2936
-4
lines changed

.github/workflows/e2e-tests.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
CORALOGIX_REGION: ${{ secrets.CORALOGIX_REGION }}
2424
CORALOGIX_API_KEY: ${{ secrets.CORALOGIX_API_KEY }}
2525
SCOPE_RECONCILE_INTERVAL_SECONDS: 30
26+
AWS_REGION: ${{ secrets.AWS_REGION }}
27+
LOGS_BUCKET: ${{ secrets.LOGS_BUCKET }}
2628
steps:
2729
- name: Checkout
2830
uses: actions/checkout@v2
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
// Copyright 2024 Coralogix Ltd.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package v1alpha1
16+
17+
import (
18+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
19+
20+
cxsdk "github.com/coralogix/coralogix-management-sdk/go"
21+
)
22+
23+
// ArchiveLogsTargetSpec defines the desired state of a Coralogix archive logs target.
24+
// +kubebuilder:validation:XValidation:rule="has(self.s3Target) != has(self.ibmCosTarget)",message="Exactly one of s3Target or ibmCosTarget must be specified"
25+
type ArchiveLogsTargetSpec struct {
26+
// The S3 target configuration.
27+
// +optional
28+
S3Target *S3Target `json:"s3Target,omitempty"`
29+
// The IBM COS target configuration.
30+
// +optional
31+
IbmCosTarget *IbmCosTarget `json:"ibmCosTarget,omitempty"`
32+
}
33+
34+
type S3Target struct {
35+
// The region of the S3 bucket.
36+
Region string `json:"region,omitempty"`
37+
Bucket string `json:"bucketName,omitempty"`
38+
}
39+
40+
type IbmCosTarget struct {
41+
// BucketCrn is the CRN of the IBM COS bucket.
42+
BucketCrn string `json:"bucketCrn,omitempty"`
43+
// Endpoint is the endpoint URL for the IBM COS service.
44+
Endpoint string `json:"endpoint,omitempty"`
45+
// ServiceCrn is the CRN of the service instance.
46+
// +optional
47+
ServiceCrn *string `json:"serviceCrn,omitempty"`
48+
// BucketType defines the type of the bucket.
49+
// +kubebuilder:validation:Enum=UNSPECIFIED;EXTERNAL;INTERNAL
50+
// +optional
51+
BucketType *string `json:"bucketType,omitempty"`
52+
}
53+
54+
type ArchiveLogsTargetStatus struct {
55+
// ID is the identifier of the archive logs target.
56+
ID *string `json:"id,omitempty"` // The ID of the archive logs target, if applicable.
57+
// +optional
58+
Conditions []metav1.Condition `json:"conditions,omitempty"`
59+
}
60+
61+
func (s *ArchiveLogsTargetSpec) ExtractSetTargetRequest(isTargetActive bool) (*cxsdk.SetTargetRequest, error) {
62+
if s.S3Target != nil {
63+
return &cxsdk.SetTargetRequest{
64+
IsActive: isTargetActive,
65+
TargetSpec: &cxsdk.SetTargetRequestS3{
66+
S3: &cxsdk.S3TargetSpec{
67+
Region: &s.S3Target.Region,
68+
Bucket: s.S3Target.Bucket,
69+
},
70+
},
71+
}, nil
72+
} else {
73+
var bucketType cxsdk.IbmBucketType
74+
if s.IbmCosTarget.BucketType != nil {
75+
switch *s.IbmCosTarget.BucketType {
76+
case "UNSPECIFIED":
77+
bucketType = cxsdk.IbmBucketTypeUnspecified
78+
case "EXTERNAL":
79+
bucketType = cxsdk.IbmBucketTypeExternal
80+
case "INTERNAL":
81+
bucketType = cxsdk.IbmBucketTypeInternal
82+
83+
}
84+
}
85+
86+
return &cxsdk.SetTargetRequest{
87+
IsActive: true,
88+
TargetSpec: &cxsdk.SetTargetRequestIbmCos{
89+
IbmCos: &cxsdk.IBMCosTargetSpec{
90+
BucketCrn: s.IbmCosTarget.BucketCrn,
91+
Endpoint: s.IbmCosTarget.Endpoint,
92+
ServiceCrn: s.IbmCosTarget.ServiceCrn,
93+
BucketType: &bucketType,
94+
},
95+
},
96+
}, nil
97+
}
98+
}
99+
100+
func (i *ArchiveLogsTarget) GetConditions() []metav1.Condition {
101+
return i.Status.Conditions
102+
}
103+
104+
func (i *ArchiveLogsTarget) SetConditions(conditions []metav1.Condition) {
105+
i.Status.Conditions = conditions
106+
}
107+
108+
// ArchiveLogsTarget is the Schema for the archive logs targets API.
109+
110+
// +kubebuilder:object:root=true
111+
// +kubebuilder:subresource:status
112+
type ArchiveLogsTarget struct {
113+
metav1.TypeMeta `json:",inline"`
114+
metav1.ObjectMeta `json:"metadata,omitempty"`
115+
116+
Spec ArchiveLogsTargetSpec `json:"spec,omitempty"`
117+
Status ArchiveLogsTargetStatus `json:"status,omitempty"`
118+
}
119+
120+
// ArchiveLogsTargetList contains a list of ArchiveLogsTarget.
121+
// +kubebuilder:object:root=true
122+
type ArchiveLogsTargetList struct {
123+
metav1.TypeMeta `json:",inline"`
124+
metav1.ListMeta `json:"metadata,omitempty"`
125+
Items []ArchiveLogsTarget `json:"items"`
126+
}
127+
128+
func init() {
129+
SchemeBuilder.Register(&ArchiveLogsTarget{}, &ArchiveLogsTargetList{})
130+
}

api/coralogix/v1alpha1/zz_generated.deepcopy.go

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

charts/coralogix-operator/templates/cluster_role.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ rules:
4949
- alerts
5050
- alertschedulers
5151
- apikeys
52+
- archivelogstargets
5253
- connectors
5354
- customroles
5455
- dashboards
@@ -80,6 +81,7 @@ rules:
8081
- alerts/finalizers
8182
- alertschedulers/finalizers
8283
- apikeys/finalizers
84+
- archivelogstargets/finalizers
8385
- connectors/finalizers
8486
- customroles/finalizers
8587
- dashboards/finalizers
@@ -105,6 +107,7 @@ rules:
105107
- alerts/status
106108
- alertschedulers/status
107109
- apikeys/status
110+
- archivelogstargets/status
108111
- connectors/status
109112
- customroles/status
110113
- dashboards/status

0 commit comments

Comments
 (0)