Skip to content

Commit e795160

Browse files
Merge pull request openstack-k8s-operators#1868 from stuggi/backup_restore_controller
[b/r] Add OpenStackBackupConfig controller and backup/restore labeling
2 parents f410b6b + 1fad42f commit e795160

63 files changed

Lines changed: 3357 additions & 35 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

PROJECT

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,13 @@ resources:
9999
kind: OpenStack
100100
path: github.com/openstack-k8s-operators/openstack-operator/api/operator/v1beta1
101101
version: v1beta1
102+
- api:
103+
crdVersion: v1
104+
namespaced: true
105+
controller: true
106+
domain: openstack.org
107+
group: backup
108+
kind: OpenStackBackupConfig
109+
path: github.com/openstack-k8s-operators/openstack-operator/api/backup/v1beta1
110+
version: v1beta1
102111
version: "3"

api/backup/v1beta1/conditions.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2026.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
21+
)
22+
23+
// Condition types for OpenStackBackupConfig
24+
const (
25+
// OpenStackBackupConfigSecretsReadyCondition - Secrets labeling status
26+
OpenStackBackupConfigSecretsReadyCondition condition.Type = "SecretsReady"
27+
28+
// OpenStackBackupConfigConfigMapsReadyCondition - ConfigMaps labeling status
29+
OpenStackBackupConfigConfigMapsReadyCondition condition.Type = "ConfigMapsReady"
30+
31+
// OpenStackBackupConfigNADsReadyCondition - NetworkAttachmentDefinitions labeling status
32+
OpenStackBackupConfigNADsReadyCondition condition.Type = "NADsReady"
33+
34+
// OpenStackBackupConfigCRsReadyCondition - CR instances labeling status
35+
OpenStackBackupConfigCRsReadyCondition condition.Type = "CRsReady"
36+
)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2026.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// Package v1beta1 contains API Schema definitions for the backup v1beta1 API group.
18+
// +kubebuilder:object:generate=true
19+
// +groupName=backup.openstack.org
20+
package v1beta1
21+
22+
import (
23+
"k8s.io/apimachinery/pkg/runtime/schema"
24+
"sigs.k8s.io/controller-runtime/pkg/scheme"
25+
)
26+
27+
var (
28+
// GroupVersion is group version used to register these objects.
29+
GroupVersion = schema.GroupVersion{Group: "backup.openstack.org", Version: "v1beta1"}
30+
31+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
32+
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
34+
// AddToScheme adds the types in this group-version to the given scheme.
35+
AddToScheme = SchemeBuilder.AddToScheme
36+
)
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*
2+
Copyright 2026.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
21+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22+
)
23+
24+
// BackupLabelingPolicy controls whether backup labeling is active for a resource type
25+
// +kubebuilder:validation:Enum=enabled;disabled
26+
type BackupLabelingPolicy string
27+
28+
const (
29+
// BackupLabelingEnabled enables backup labeling for the resource type
30+
BackupLabelingEnabled BackupLabelingPolicy = "enabled"
31+
// BackupLabelingDisabled disables backup labeling for the resource type
32+
BackupLabelingDisabled BackupLabelingPolicy = "disabled"
33+
)
34+
35+
// OpenStackBackupConfigSpec defines the desired state of OpenStackBackupConfig.
36+
type OpenStackBackupConfigSpec struct {
37+
// DefaultRestoreOrder is the restore order assigned to user-provided resources
38+
// +kubebuilder:validation:Optional
39+
// +kubebuilder:default="10"
40+
DefaultRestoreOrder string `json:"defaultRestoreOrder"`
41+
42+
// Secrets configuration for backup labeling
43+
// +kubebuilder:validation:Optional
44+
// +kubebuilder:default={labeling:enabled}
45+
Secrets ResourceBackupConfig `json:"secrets"`
46+
47+
// ConfigMaps configuration for backup labeling
48+
// Defaults: Excludes kube-root-ca.crt and openshift-service-ca.crt
49+
// +kubebuilder:validation:Optional
50+
// +kubebuilder:default={labeling:enabled,excludeNames:{"kube-root-ca.crt","openshift-service-ca.crt"}}
51+
ConfigMaps ResourceBackupConfig `json:"configMaps"`
52+
53+
// NetworkAttachmentDefinitions configuration for backup labeling
54+
// +kubebuilder:validation:Optional
55+
// +kubebuilder:default={labeling:enabled}
56+
NetworkAttachmentDefinitions ResourceBackupConfig `json:"networkAttachmentDefinitions"`
57+
58+
}
59+
60+
// ResourceBackupConfig defines backup labeling rules for a resource type
61+
type ResourceBackupConfig struct {
62+
// Labeling controls whether to label this resource type for backup
63+
// +kubebuilder:validation:Optional
64+
Labeling *BackupLabelingPolicy `json:"labeling,omitempty"`
65+
66+
// RestoreOrder overrides the default restore order for this resource type.
67+
// If empty, the global DefaultRestoreOrder is used.
68+
// +kubebuilder:validation:Optional
69+
RestoreOrder string `json:"restoreOrder,omitempty"`
70+
71+
// ExcludeLabelKeys is a list of label keys - resources with any of these labels are excluded
72+
// Example: ["service-cert", "osdp-service"] excludes service-cert and dataplane service secrets
73+
// +kubebuilder:validation:Optional
74+
ExcludeLabelKeys []string `json:"excludeLabelKeys,omitempty"`
75+
76+
// ExcludeNames is a list of resource names to exclude from backup labeling
77+
// Example: ["kube-root-ca.crt", "openshift-service-ca.crt"] for system ConfigMaps
78+
// +kubebuilder:validation:Optional
79+
ExcludeNames []string `json:"excludeNames,omitempty"`
80+
81+
// IncludeLabelSelector allows filtering resources by label selector
82+
// Only resources matching this selector will be labeled (in addition to ownerRef check)
83+
// +kubebuilder:validation:Optional
84+
IncludeLabelSelector map[string]string `json:"includeLabelSelector,omitempty"`
85+
}
86+
87+
// OpenStackBackupConfigStatus defines the observed state of OpenStackBackupConfig.
88+
type OpenStackBackupConfigStatus struct {
89+
// LabeledResources tracks how many resources of each type were labeled
90+
// +kubebuilder:validation:Optional
91+
LabeledResources ResourceCounts `json:"labeledResources,omitempty"`
92+
93+
// Conditions represents the latest available observations of the resource's current state
94+
// +operator-sdk:csv:customresourcedefinitions:type=status
95+
Conditions condition.Conditions `json:"conditions,omitempty"`
96+
}
97+
98+
// ResourceCounts tracks labeled resource counts by type
99+
type ResourceCounts struct {
100+
// Secrets is the number of secrets labeled for backup
101+
// +kubebuilder:validation:Optional
102+
Secrets int `json:"secrets"`
103+
104+
// ConfigMaps is the number of configmaps labeled for backup
105+
// +kubebuilder:validation:Optional
106+
ConfigMaps int `json:"configMaps"`
107+
108+
// NetworkAttachmentDefinitions is the number of NADs labeled for backup
109+
// +kubebuilder:validation:Optional
110+
NetworkAttachmentDefinitions int `json:"networkAttachmentDefinitions"`
111+
112+
// CRs is the number of CR instances labeled for backup
113+
// +kubebuilder:validation:Optional
114+
CRs int `json:"crs"`
115+
}
116+
117+
// +kubebuilder:object:root=true
118+
// +kubebuilder:subresource:status
119+
// +kubebuilder:resource:shortName=osbkpcfg;osbackupcfg;osbackupconfig
120+
// +kubebuilder:printcolumn:name="Secrets",type="integer",JSONPath=".status.labeledResources.secrets",description="Labeled Secrets"
121+
// +kubebuilder:printcolumn:name="ConfigMaps",type="integer",JSONPath=".status.labeledResources.configMaps",description="Labeled ConfigMaps"
122+
// +kubebuilder:printcolumn:name="NADs",type="integer",JSONPath=".status.labeledResources.networkAttachmentDefinitions",description="Labeled NADs"
123+
// +kubebuilder:printcolumn:name="CRs",type="integer",JSONPath=".status.labeledResources.crs",description="Labeled CR instances"
124+
// +kubebuilder:metadata:labels=backup.openstack.org/restore=true
125+
// +kubebuilder:metadata:labels=backup.openstack.org/category=controlplane
126+
// +kubebuilder:metadata:labels=backup.openstack.org/restore-order=20
127+
128+
// OpenStackBackupConfig is the Schema for the openstackbackupconfigs API.
129+
// It configures automatic backup labeling for user-provided resources (without ownerReferences).
130+
type OpenStackBackupConfig struct {
131+
metav1.TypeMeta `json:",inline"`
132+
metav1.ObjectMeta `json:"metadata,omitempty"`
133+
134+
Spec OpenStackBackupConfigSpec `json:"spec,omitempty"`
135+
Status OpenStackBackupConfigStatus `json:"status,omitempty"`
136+
}
137+
138+
// +kubebuilder:object:root=true
139+
140+
// OpenStackBackupConfigList contains a list of OpenStackBackupConfig.
141+
type OpenStackBackupConfigList struct {
142+
metav1.TypeMeta `json:",inline"`
143+
metav1.ListMeta `json:"metadata,omitempty"`
144+
Items []OpenStackBackupConfig `json:"items"`
145+
}
146+
147+
func init() {
148+
SchemeBuilder.Register(&OpenStackBackupConfig{}, &OpenStackBackupConfigList{})
149+
}

0 commit comments

Comments
 (0)