Skip to content

CLOUDP-323997: Split mongodb_types into smaller files #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions api/v1/mdb/mongodb_agent_config_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package mdb

import (
"fmt"
"sort"
"strings"

"github.com/mongodb/mongodb-kubernetes/mongodb-community-operator/pkg/automationconfig"
)

type AgentConfig struct {
// +optional
BackupAgent BackupAgent `json:"backupAgent,omitempty"`
// +optional
MonitoringAgent MonitoringAgent `json:"monitoringAgent,omitempty"`
// +optional
Mongod AgentLoggingMongodConfig `json:"mongod,omitempty"`
// +optional
ReadinessProbe ReadinessProbe `json:"readinessProbe,omitempty"`
// +optional
StartupParameters StartupParameters `json:"startupOptions"`
// +optional
LogLevel LogLevel `json:"logLevel"`
// +optional
MaxLogFileDurationHours int `json:"maxLogFileDurationHours"`
// DEPRECATED please use mongod.logRotate
// +optional
LogRotate *automationconfig.CrdLogRotate `json:"logRotate,omitempty"`
// DEPRECATED please use mongod.systemLog
// +optional
SystemLog *automationconfig.SystemLog `json:"systemLog,omitempty"`
}

// AgentLoggingMongodConfig contain settings for the mongodb processes configured by the agent
type AgentLoggingMongodConfig struct {
// +optional
// LogRotate configures log rotation for the mongodb processes
LogRotate *automationconfig.CrdLogRotate `json:"logRotate,omitempty"`

// LogRotate configures audit log rotation for the mongodb processes
AuditLogRotate *automationconfig.CrdLogRotate `json:"auditlogRotate,omitempty"`

// +optional
// SystemLog configures system log of mongod
SystemLog *automationconfig.SystemLog `json:"systemLog,omitempty"`
}

type BackupAgent struct {
// +optional
// LogRotate configures log rotation for the BackupAgent processes
LogRotate *LogRotateForBackupAndMonitoring `json:"logRotate,omitempty"`
}

type MonitoringAgent struct {
// +optional
// LogRotate configures log rotation for the BackupAgent processes
LogRotate *LogRotateForBackupAndMonitoring `json:"logRotate,omitempty"`
}

type LogRotateForBackupAndMonitoring struct {
// Maximum size for an individual log file before rotation.
// OM only supports ints
SizeThresholdMB int `json:"sizeThresholdMB,omitempty"`
// Number of hours after which this MongoDB Agent rotates the log file.
TimeThresholdHrs int `json:"timeThresholdHrs,omitempty"`
}

// StartupParameters can be used to configure the startup parameters with which the agent starts. That also contains
// log rotation settings as defined here:
type StartupParameters map[string]string

type MonitoringAgentConfig struct {
StartupParameters StartupParameters `json:"startupOptions"`
}

type EnvironmentVariables map[string]string

type ReadinessProbe struct {
EnvironmentVariables `json:"environmentVariables,omitempty"`
}

func (a *AgentLoggingMongodConfig) HasLoggingConfigured() bool {
if a.LogRotate != nil || a.AuditLogRotate != nil || a.SystemLog != nil {
return true
}
return false
}

func (s StartupParameters) ToCommandLineArgs() string {
var keys []string
for k := range s {
keys = append(keys, k)
}

// order must be preserved to ensure the same set of command line arguments
// results in the same StatefulSet template spec.
sort.SliceStable(keys, func(i, j int) bool {
return keys[i] < keys[j]
})

sb := strings.Builder{}
for _, key := range keys {
if value := s[key]; value != "" {
sb.Write([]byte(fmt.Sprintf(" -%s=%s", key, value)))
} else {
sb.Write([]byte(fmt.Sprintf(" -%s", key)))
}
}
return sb.String()
}
114 changes: 114 additions & 0 deletions api/v1/mdb/mongodb_backup_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package mdb

import v1 "github.com/mongodb/mongodb-kubernetes/api/v1"

type BackupMode string

// Backup contains configuration options for configuring
// backup for this MongoDB resource
type Backup struct {
// +kubebuilder:validation:Enum=enabled;disabled;terminated
// +optional
Mode BackupMode `json:"mode"`

// AutoTerminateOnDeletion indicates if the Operator should stop and terminate the Backup before the cleanup,
// when the MongoDB CR is deleted
// +optional
AutoTerminateOnDeletion bool `json:"autoTerminateOnDeletion,omitempty"`

// +optional
SnapshotSchedule *SnapshotSchedule `json:"snapshotSchedule,omitempty"`

// Encryption settings
// +optional
Encryption *Encryption `json:"encryption,omitempty"`

// Assignment Labels set in the Ops Manager
// +optional
AssignmentLabels []string `json:"assignmentLabels,omitempty"`
}

type SnapshotSchedule struct {
// Number of hours between snapshots.
// +kubebuilder:validation:Enum=6;8;12;24
// +optional
SnapshotIntervalHours *int `json:"snapshotIntervalHours,omitempty"`

// Number of days to keep recent snapshots.
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=365
// +optional
SnapshotRetentionDays *int `json:"snapshotRetentionDays,omitempty"`

// Number of days to retain daily snapshots. Setting 0 will disable this rule.
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=365
// +optional
DailySnapshotRetentionDays *int `json:"dailySnapshotRetentionDays"`

// Number of weeks to retain weekly snapshots. Setting 0 will disable this rule
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=365
// +optional
WeeklySnapshotRetentionWeeks *int `json:"weeklySnapshotRetentionWeeks,omitempty"`
// Number of months to retain weekly snapshots. Setting 0 will disable this rule.
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=36
// +optional
MonthlySnapshotRetentionMonths *int `json:"monthlySnapshotRetentionMonths,omitempty"`
// Number of hours in the past for which a point-in-time snapshot can be created.
// +kubebuilder:validation:Enum=1;2;3;4;5;6;7;15;30;60;90;120;180;360
// +optional
PointInTimeWindowHours *int `json:"pointInTimeWindowHours,omitempty"`

// Hour of the day to schedule snapshots using a 24-hour clock, in UTC.
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=23
// +optional
ReferenceHourOfDay *int `json:"referenceHourOfDay,omitempty"`

// Minute of the hour to schedule snapshots, in UTC.
// +kubebuilder:validation:Minimum=0
// +kubebuilder:validation:Maximum=59
// +optional
ReferenceMinuteOfHour *int `json:"referenceMinuteOfHour,omitempty"`

// 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.
// +kubebuilder:validation:Enum=SUNDAY;MONDAY;TUESDAY;WEDNESDAY;THURSDAY;FRIDAY;SATURDAY
// +optional
FullIncrementalDayOfWeek *string `json:"fullIncrementalDayOfWeek,omitempty"`

// +kubebuilder:validation:Enum=15;30;60
ClusterCheckpointIntervalMin *int `json:"clusterCheckpointIntervalMin,omitempty"`
}

type BackupStatus struct {
StatusName string `json:"statusName"`
}

// Encryption contains encryption settings
type Encryption struct {
// Kmip corresponds to the KMIP configuration assigned to the Ops Manager Project's configuration.
// +optional
Kmip *KmipConfig `json:"kmip,omitempty"`
}

// KmipConfig contains Project-level KMIP configuration
type KmipConfig struct {
// KMIP Client configuration
Client v1.KmipClientConfig `json:"client"`
}

func (b *Backup) IsKmipEnabled() bool {
if b.Encryption == nil || b.Encryption.Kmip == nil {
return false
}
return true
}

func (b *Backup) GetKmip() *KmipConfig {
if !b.IsKmipEnabled() {
return nil
}
return b.Encryption.Kmip
}
Loading