Skip to content

Commit 77f218c

Browse files
committed
Move fields in new files
1 parent 7a73bf1 commit 77f218c

File tree

4 files changed

+680
-664
lines changed

4 files changed

+680
-664
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
package mdb
2+
3+
import (
4+
"fmt"
5+
"github.com/mongodb/mongodb-kubernetes/mongodb-community-operator/pkg/automationconfig"
6+
"sort"
7+
"strings"
8+
)
9+
10+
type AgentConfig struct {
11+
// +optional
12+
BackupAgent BackupAgent `json:"backupAgent,omitempty"`
13+
// +optional
14+
MonitoringAgent MonitoringAgent `json:"monitoringAgent,omitempty"`
15+
// +optional
16+
Mongod AgentLoggingMongodConfig `json:"mongod,omitempty"`
17+
// +optional
18+
ReadinessProbe ReadinessProbe `json:"readinessProbe,omitempty"`
19+
// +optional
20+
StartupParameters StartupParameters `json:"startupOptions"`
21+
// +optional
22+
LogLevel LogLevel `json:"logLevel"`
23+
// +optional
24+
MaxLogFileDurationHours int `json:"maxLogFileDurationHours"`
25+
// DEPRECATED please use mongod.logRotate
26+
// +optional
27+
LogRotate *automationconfig.CrdLogRotate `json:"logRotate,omitempty"`
28+
// DEPRECATED please use mongod.systemLog
29+
// +optional
30+
SystemLog *automationconfig.SystemLog `json:"systemLog,omitempty"`
31+
}
32+
33+
// AgentLoggingMongodConfig contain settings for the mongodb processes configured by the agent
34+
type AgentLoggingMongodConfig struct {
35+
// +optional
36+
// LogRotate configures log rotation for the mongodb processes
37+
LogRotate *automationconfig.CrdLogRotate `json:"logRotate,omitempty"`
38+
39+
// LogRotate configures audit log rotation for the mongodb processes
40+
AuditLogRotate *automationconfig.CrdLogRotate `json:"auditlogRotate,omitempty"`
41+
42+
// +optional
43+
// SystemLog configures system log of mongod
44+
SystemLog *automationconfig.SystemLog `json:"systemLog,omitempty"`
45+
}
46+
47+
type BackupAgent struct {
48+
// +optional
49+
// LogRotate configures log rotation for the BackupAgent processes
50+
LogRotate *LogRotateForBackupAndMonitoring `json:"logRotate,omitempty"`
51+
}
52+
53+
type MonitoringAgent struct {
54+
// +optional
55+
// LogRotate configures log rotation for the BackupAgent processes
56+
LogRotate *LogRotateForBackupAndMonitoring `json:"logRotate,omitempty"`
57+
}
58+
59+
type LogRotateForBackupAndMonitoring struct {
60+
// Maximum size for an individual log file before rotation.
61+
// OM only supports ints
62+
SizeThresholdMB int `json:"sizeThresholdMB,omitempty"`
63+
// Number of hours after which this MongoDB Agent rotates the log file.
64+
TimeThresholdHrs int `json:"timeThresholdHrs,omitempty"`
65+
}
66+
67+
// StartupParameters can be used to configure the startup parameters with which the agent starts. That also contains
68+
// log rotation settings as defined here:
69+
type StartupParameters map[string]string
70+
71+
type MonitoringAgentConfig struct {
72+
StartupParameters StartupParameters `json:"startupOptions"`
73+
}
74+
75+
type EnvironmentVariables map[string]string
76+
77+
type ReadinessProbe struct {
78+
EnvironmentVariables `json:"environmentVariables,omitempty"`
79+
}
80+
81+
func (a *AgentLoggingMongodConfig) HasLoggingConfigured() bool {
82+
if a.LogRotate != nil || a.AuditLogRotate != nil || a.SystemLog != nil {
83+
return true
84+
}
85+
return false
86+
}
87+
88+
func (s StartupParameters) ToCommandLineArgs() string {
89+
var keys []string
90+
for k := range s {
91+
keys = append(keys, k)
92+
}
93+
94+
// order must be preserved to ensure the same set of command line arguments
95+
// results in the same StatefulSet template spec.
96+
sort.SliceStable(keys, func(i, j int) bool {
97+
return keys[i] < keys[j]
98+
})
99+
100+
sb := strings.Builder{}
101+
for _, key := range keys {
102+
if value := s[key]; value != "" {
103+
sb.Write([]byte(fmt.Sprintf(" -%s=%s", key, value)))
104+
} else {
105+
sb.Write([]byte(fmt.Sprintf(" -%s", key)))
106+
}
107+
}
108+
return sb.String()
109+
}

api/v1/mdb/mongodb_backup_types.go

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package mdb
2+
3+
import v1 "github.com/mongodb/mongodb-kubernetes/api/v1"
4+
5+
type BackupMode string
6+
7+
// Backup contains configuration options for configuring
8+
// backup for this MongoDB resource
9+
type Backup struct {
10+
// +kubebuilder:validation:Enum=enabled;disabled;terminated
11+
// +optional
12+
Mode BackupMode `json:"mode"`
13+
14+
// AutoTerminateOnDeletion indicates if the Operator should stop and terminate the Backup before the cleanup,
15+
// when the MongoDB CR is deleted
16+
// +optional
17+
AutoTerminateOnDeletion bool `json:"autoTerminateOnDeletion,omitempty"`
18+
19+
// +optional
20+
SnapshotSchedule *SnapshotSchedule `json:"snapshotSchedule,omitempty"`
21+
22+
// Encryption settings
23+
// +optional
24+
Encryption *Encryption `json:"encryption,omitempty"`
25+
26+
// Assignment Labels set in the Ops Manager
27+
// +optional
28+
AssignmentLabels []string `json:"assignmentLabels,omitempty"`
29+
}
30+
31+
type SnapshotSchedule struct {
32+
// Number of hours between snapshots.
33+
// +kubebuilder:validation:Enum=6;8;12;24
34+
// +optional
35+
SnapshotIntervalHours *int `json:"snapshotIntervalHours,omitempty"`
36+
37+
// Number of days to keep recent snapshots.
38+
// +kubebuilder:validation:Minimum=1
39+
// +kubebuilder:validation:Maximum=365
40+
// +optional
41+
SnapshotRetentionDays *int `json:"snapshotRetentionDays,omitempty"`
42+
43+
// Number of days to retain daily snapshots. Setting 0 will disable this rule.
44+
// +kubebuilder:validation:Minimum=0
45+
// +kubebuilder:validation:Maximum=365
46+
// +optional
47+
DailySnapshotRetentionDays *int `json:"dailySnapshotRetentionDays"`
48+
49+
// Number of weeks to retain weekly snapshots. Setting 0 will disable this rule
50+
// +kubebuilder:validation:Minimum=0
51+
// +kubebuilder:validation:Maximum=365
52+
// +optional
53+
WeeklySnapshotRetentionWeeks *int `json:"weeklySnapshotRetentionWeeks,omitempty"`
54+
// Number of months to retain weekly snapshots. Setting 0 will disable this rule.
55+
// +kubebuilder:validation:Minimum=0
56+
// +kubebuilder:validation:Maximum=36
57+
// +optional
58+
MonthlySnapshotRetentionMonths *int `json:"monthlySnapshotRetentionMonths,omitempty"`
59+
// Number of hours in the past for which a point-in-time snapshot can be created.
60+
// +kubebuilder:validation:Enum=1;2;3;4;5;6;7;15;30;60;90;120;180;360
61+
// +optional
62+
PointInTimeWindowHours *int `json:"pointInTimeWindowHours,omitempty"`
63+
64+
// Hour of the day to schedule snapshots using a 24-hour clock, in UTC.
65+
// +kubebuilder:validation:Minimum=0
66+
// +kubebuilder:validation:Maximum=23
67+
// +optional
68+
ReferenceHourOfDay *int `json:"referenceHourOfDay,omitempty"`
69+
70+
// Minute of the hour to schedule snapshots, in UTC.
71+
// +kubebuilder:validation:Minimum=0
72+
// +kubebuilder:validation:Maximum=59
73+
// +optional
74+
ReferenceMinuteOfHour *int `json:"referenceMinuteOfHour,omitempty"`
75+
76+
// Day of the week when Ops Manager takes a full snapshot. This ensures a recent complete backup. Ops Manager sets the default value to SUNDAY.
77+
// +kubebuilder:validation:Enum=SUNDAY;MONDAY;TUESDAY;WEDNESDAY;THURSDAY;FRIDAY;SATURDAY
78+
// +optional
79+
FullIncrementalDayOfWeek *string `json:"fullIncrementalDayOfWeek,omitempty"`
80+
81+
// +kubebuilder:validation:Enum=15;30;60
82+
ClusterCheckpointIntervalMin *int `json:"clusterCheckpointIntervalMin,omitempty"`
83+
}
84+
85+
type BackupStatus struct {
86+
StatusName string `json:"statusName"`
87+
}
88+
89+
// Encryption contains encryption settings
90+
type Encryption struct {
91+
// Kmip corresponds to the KMIP configuration assigned to the Ops Manager Project's configuration.
92+
// +optional
93+
Kmip *KmipConfig `json:"kmip,omitempty"`
94+
}
95+
96+
// KmipConfig contains Project-level KMIP configuration
97+
type KmipConfig struct {
98+
// KMIP Client configuration
99+
Client v1.KmipClientConfig `json:"client"`
100+
}
101+
102+
func (b *Backup) IsKmipEnabled() bool {
103+
if b.Encryption == nil || b.Encryption.Kmip == nil {
104+
return false
105+
}
106+
return true
107+
}
108+
109+
func (b *Backup) GetKmip() *KmipConfig {
110+
if !b.IsKmipEnabled() {
111+
return nil
112+
}
113+
return b.Encryption.Kmip
114+
}

0 commit comments

Comments
 (0)