Skip to content

Commit

Permalink
Captured BackupService, Backup, Restore, PDB, ReplicaSet and ConfigMa…
Browse files Browse the repository at this point in the history
…p related information
  • Loading branch information
jwalantmodi05 committed Nov 4, 2024
1 parent 42b4f0b commit a56c011
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 35 deletions.
4 changes: 3 additions & 1 deletion cmd/collectinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ var collectinfoCmd = &cobra.Command{
Use: "collectinfo",
Short: "collectinfo command collects all the required info from kubernetes cluster",
Long: `This command collects the following data from the given namespaces:
* pods, statefulsets, persistentvolumeclaims, aerospikeclusters, nodes, storageclasses objects.
* pods, statefulsets, deployments, persistentvolumeclaims, aerospikeclusters, aerospikebackupservices,
* aerospikebackups, aerospikerestores, configmaps, replicasets, poddisruptionbudgets, services,
* nodes, storageclasses, persistentvolumes objects.
* mutating and validating webhooks configurations.
* containers logs.
* events logs.`,
Expand Down
128 changes: 117 additions & 11 deletions pkg/collectinfo/collectinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ import (
admissionv1 "k8s.io/api/admissionregistration/v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
policyv1 "k8s.io/api/policy/v1"
v1 "k8s.io/api/storage/v1"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/intstr"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/aerospike/aerospike-kubernetes-operator-ctl/pkg/collectinfo"
Expand All @@ -42,16 +44,22 @@ import (
)

const (
nodeName = "test-node"
scName = "test-sc"
serviceName = "test-service"
pvcName = "test-pvc"
pvName = "test-pv"
stsName = "test-sts"
deployName = "test-deploy"
podName = "test-pod"
containerName = "test-container"
aerospikeClusterName = "test-aerocluster"
nodeName = "test-node"
scName = "test-sc"
serviceName = "test-service"
pvcName = "test-pvc"
pvName = "test-pv"
stsName = "test-sts"
deployName = "test-deploy"
podName = "test-pod"
containerName = "test-container"
aerospikeClusterName = "test-aerocluster"
aerospikeBackupServiceName = "test-aerobackupservice"
aerospikeBackupName = "test-aerobackup"
aerospikeRestoreName = "test-aerorestore"
pdbName = "test-pdb"
cmName = "test-cm"
rsName = "test-rs"
)

var (
Expand Down Expand Up @@ -89,6 +97,18 @@ var filesList = map[string]bool{
serviceName+collectinfo.FileSuffix): false,
filepath.Join(namespaceScopeDir, namespace, collectinfo.KindDirNames[internal.AerospikeClusterKind],
aerospikeClusterName+collectinfo.FileSuffix): false,
filepath.Join(namespaceScopeDir, namespace, collectinfo.KindDirNames[internal.AerospikeBackupServiceKind],
aerospikeBackupServiceName+collectinfo.FileSuffix): false,
filepath.Join(namespaceScopeDir, namespace, collectinfo.KindDirNames[internal.AerospikeBackupKind],
aerospikeBackupName+collectinfo.FileSuffix): false,
filepath.Join(namespaceScopeDir, namespace, collectinfo.KindDirNames[internal.AerospikeRestoreKind],
aerospikeRestoreName+collectinfo.FileSuffix): false,
filepath.Join(namespaceScopeDir, namespace, collectinfo.KindDirNames[internal.PodDisruptionBudgetKind],
pdbName+collectinfo.FileSuffix): false,
filepath.Join(namespaceScopeDir, namespace, collectinfo.KindDirNames[internal.ConfigMapKind],
cmName+collectinfo.FileSuffix): false,
filepath.Join(namespaceScopeDir, namespace, collectinfo.KindDirNames[internal.RSKind],
rsName+collectinfo.FileSuffix): false,
filepath.Join(namespaceScopeDir, namespace, collectinfo.SummaryDir,
collectinfo.SummaryFile): false,
filepath.Join(collectinfo.RootOutputDir,
Expand Down Expand Up @@ -233,7 +253,7 @@ var _ = Describe("collectInfo", func() {
gvk := schema.GroupVersionKind{
Group: "asdb.aerospike.com",
Version: "v1",
Kind: "AerospikeCluster",
Kind: internal.AerospikeClusterKind,
}

u := &unstructured.Unstructured{}
Expand All @@ -244,6 +264,92 @@ var _ = Describe("collectInfo", func() {
err = k8sClient.Create(context.TODO(), u)
Expect(err).ToNot(HaveOccurred())

gvk = schema.GroupVersionKind{
Group: "asdb.aerospike.com",
Version: "v1beta1",
Kind: internal.AerospikeBackupServiceKind,
}

u = &unstructured.Unstructured{}
u.SetName(aerospikeBackupServiceName)
u.SetNamespace(namespace)
u.SetGroupVersionKind(gvk)

err = k8sClient.Create(context.TODO(), u)
Expect(err).ToNot(HaveOccurred())

gvk = schema.GroupVersionKind{
Group: "asdb.aerospike.com",
Version: "v1beta1",
Kind: internal.AerospikeBackupKind,
}

u = &unstructured.Unstructured{}
u.SetName(aerospikeBackupName)
u.SetNamespace(namespace)
u.SetGroupVersionKind(gvk)

err = k8sClient.Create(context.TODO(), u)
Expect(err).ToNot(HaveOccurred())

gvk = schema.GroupVersionKind{
Group: "asdb.aerospike.com",
Version: "v1beta1",
Kind: internal.AerospikeRestoreKind,
}

u = &unstructured.Unstructured{}
u.SetName(aerospikeRestoreName)
u.SetNamespace(namespace)
u.SetGroupVersionKind(gvk)

err = k8sClient.Create(context.TODO(), u)
Expect(err).ToNot(HaveOccurred())

rs := &appsv1.ReplicaSet{
ObjectMeta: metav1.ObjectMeta{Name: rsName, Namespace: namespace},
Spec: appsv1.ReplicaSetSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{"app": "t1", "s2iBuilder": "t1-s2i-1x55", "version": "v1"},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{"app": "t1", "s2iBuilder": "t1-s2i-1x55", "version": "v1"},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: containerName,
Image: "nginx:1.12",
},
},
},
},
},
}

err = k8sClient.Create(context.TODO(), rs, createOption)
Expect(err).ToNot(HaveOccurred())

maxUnavailable := intstr.FromInt32(1)
pdb := &policyv1.PodDisruptionBudget{
ObjectMeta: metav1.ObjectMeta{Name: pdbName, Namespace: namespace},
Spec: policyv1.PodDisruptionBudgetSpec{
MaxUnavailable: &maxUnavailable,
},
}

err = k8sClient.Create(context.TODO(), pdb, createOption)
Expect(err).ToNot(HaveOccurred())

cm := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{Name: cmName, Namespace: namespace},
Data: map[string]string{},
}

err = k8sClient.Create(context.TODO(), cm, createOption)
Expect(err).ToNot(HaveOccurred())

err = os.MkdirAll(collectinfo.RootOutputDir, os.ModePerm)
Expect(err).ToNot(HaveOccurred())

Expand Down
52 changes: 38 additions & 14 deletions pkg/collectinfo/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,65 @@ limitations under the License.
package collectinfo

import (
"github.com/aerospike/aerospike-kubernetes-operator-ctl/pkg/internal"
admissionv1 "k8s.io/api/admissionregistration/v1"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
policyv1 "k8s.io/api/policy/v1"
v1 "k8s.io/api/storage/v1"
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/aerospike/aerospike-kubernetes-operator-ctl/pkg/internal"
)

var (
KindDirNames = map[string]string{
internal.NodeKind: "nodes",
internal.PVCKind: "persistentvolumeclaims",
internal.PVKind: "persistentvolumes",
internal.STSKind: "statefulsets",
internal.DeployKind: "deployments",
internal.SCKind: "storageclasses",
internal.AerospikeClusterKind: "aerospikeclusters",
internal.PodKind: "pods",
internal.EventKind: "events",
internal.MutatingWebhookKind: "mutatingwebhookconfigurations",
internal.ValidatingWebhookKind: "validatingwebhookconfigurations",
internal.ServiceKind: "services",
internal.NodeKind: "nodes",
internal.PVCKind: "persistentvolumeclaims",
internal.PVKind: "persistentvolumes",
internal.STSKind: "statefulsets",
internal.DeployKind: "deployments",
internal.SCKind: "storageclasses",
internal.AerospikeClusterKind: "aerospikeclusters",
internal.PodKind: "pods",
internal.EventKind: "events",
internal.MutatingWebhookKind: "mutatingwebhookconfigurations",
internal.ValidatingWebhookKind: "validatingwebhookconfigurations",
internal.ServiceKind: "services",
internal.AerospikeBackupServiceKind: "aerospikebackupservices",
internal.AerospikeBackupKind: "aerospikebackups",
internal.AerospikeRestoreKind: "aerospikerestores",
internal.PodDisruptionBudgetKind: "poddisruptionbudgets",
internal.ConfigMapKind: "configmaps",
internal.RSKind: "replicasets",
}
gvkListNSScoped = []schema.GroupVersionKind{
{
Group: "asdb.aerospike.com",
Version: "v1",
Kind: internal.AerospikeClusterKind,
},
{
Group: "asdb.aerospike.com",
Version: "v1beta1",
Kind: internal.AerospikeBackupServiceKind,
},
{
Group: "asdb.aerospike.com",
Version: "v1beta1",
Kind: internal.AerospikeBackupKind,
},
{
Group: "asdb.aerospike.com",
Version: "v1beta1",
Kind: internal.AerospikeRestoreKind,
},
appsv1.SchemeGroupVersion.WithKind(internal.STSKind),
appsv1.SchemeGroupVersion.WithKind(internal.DeployKind),
appsv1.SchemeGroupVersion.WithKind(internal.RSKind),
corev1.SchemeGroupVersion.WithKind(internal.PodKind),
corev1.SchemeGroupVersion.WithKind(internal.PVCKind),
corev1.SchemeGroupVersion.WithKind(internal.ServiceKind),
policyv1.SchemeGroupVersion.WithKind(internal.PodDisruptionBudgetKind),
corev1.SchemeGroupVersion.WithKind(internal.ConfigMapKind),
}
gvkListClusterScoped = []schema.GroupVersionKind{
corev1.SchemeGroupVersion.WithKind(internal.NodeKind),
Expand Down
24 changes: 15 additions & 9 deletions pkg/internal/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@ package internal

const (
// Namespace scope resources
PodKind = "Pod"
STSKind = "StatefulSet"
DeployKind = "Deployment"
ServiceAccountKind = "ServiceAccount"
ServiceKind = "Service"
AerospikeClusterKind = "AerospikeCluster"
PVCKind = "PersistentVolumeClaim"
EventKind = "Event"
RoleBindingKind = "RoleBinding"
PodKind = "Pod"
STSKind = "StatefulSet"
RSKind = "ReplicaSet"
DeployKind = "Deployment"
ServiceAccountKind = "ServiceAccount"
ServiceKind = "Service"
AerospikeClusterKind = "AerospikeCluster"
PVCKind = "PersistentVolumeClaim"
EventKind = "Event"
RoleBindingKind = "RoleBinding"
AerospikeBackupKind = "AerospikeBackup"
AerospikeRestoreKind = "AerospikeRestore"
AerospikeBackupServiceKind = "AerospikeBackupService"
PodDisruptionBudgetKind = "PodDisruptionBudget"
ConfigMapKind = "ConfigMap"

// Cluster scope resources
NodeKind = "Node"
Expand Down

0 comments on commit a56c011

Please sign in to comment.