Skip to content
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

KO-353: Capture BackupService, Backup, Restore, PDB, ReplicaSet and ConfigMap related information #18

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
16 changes: 11 additions & 5 deletions cmd/collectinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,17 @@ var (
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.
* mutating and validating webhooks configurations.
* containers logs.
* events logs.`,
Long: `This command collects:
Following resources from the given namespaces:
* pods, statefulsets, deployments, persistentvolumeclaims, aerospikeclusters,
aerospikebackupservices, aerospikebackups, aerospikerestores, configmaps,
poddisruptionbudgets and services.

Following resources from the cluster:
* nodes, storageclasses, persistentvolumes, mutatingwebhookconfigurations
and validatingwebhookconfigurations.

Containers logs and events logs.`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.TODO()
params, err := configuration.NewParams(ctx, kubeconfig, namespaces, allNamespaces, clusterScope)
Expand Down
98 changes: 81 additions & 17 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,21 @@ 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"
)

var (
Expand Down Expand Up @@ -89,6 +96,16 @@ 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.SummaryDir,
collectinfo.SummaryFile): false,
filepath.Join(collectinfo.RootOutputDir,
Expand Down Expand Up @@ -231,17 +248,54 @@ var _ = Describe("collectInfo", func() {
Expect(err).ToNot(HaveOccurred())

gvk := schema.GroupVersionKind{
Group: "asdb.aerospike.com",
Group: internal.Group,
Version: "v1",
Kind: "AerospikeCluster",
Kind: internal.AerospikeClusterKind,
}

u := &unstructured.Unstructured{}
u.SetName(aerospikeClusterName)
u.SetNamespace(namespace)
u.SetGroupVersionKind(gvk)
createUnstructuredObject(aerospikeClusterName, namespace, gvk)

err = k8sClient.Create(context.TODO(), u)
gvk = schema.GroupVersionKind{
Group: internal.Group,
Version: internal.BetaVersion,
Kind: internal.AerospikeBackupServiceKind,
}

createUnstructuredObject(aerospikeBackupServiceName, namespace, gvk)

gvk = schema.GroupVersionKind{
Group: internal.Group,
Version: internal.BetaVersion,
Kind: internal.AerospikeBackupKind,
}

createUnstructuredObject(aerospikeBackupName, namespace, gvk)

gvk = schema.GroupVersionKind{
Group: internal.Group,
Version: internal.BetaVersion,
Kind: internal.AerospikeRestoreKind,
}

createUnstructuredObject(aerospikeRestoreName, namespace, gvk)

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)
Expand Down Expand Up @@ -319,3 +373,13 @@ func validateAndDeleteTar(srcFile string, filesList map[string]bool) error {

return os.Remove(srcFile)
}

func createUnstructuredObject(name, namespace string, gvk schema.GroupVersionKind) {
u := &unstructured.Unstructured{}
u.SetName(name)
u.SetNamespace(namespace)
u.SetGroupVersionKind(gvk)

err := k8sClient.Create(context.TODO(), u)
Expect(err).ToNot(HaveOccurred())
}
49 changes: 36 additions & 13 deletions pkg/collectinfo/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ 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/runtime/schema"

Expand All @@ -27,30 +28,52 @@ import (

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",
}
gvkListNSScoped = []schema.GroupVersionKind{
{
Group: "asdb.aerospike.com",
Group: internal.Group,
Version: "v1",
Kind: internal.AerospikeClusterKind,
},
{
Group: internal.Group,
Version: internal.BetaVersion,
Kind: internal.AerospikeBackupServiceKind,
},
{
Group: internal.Group,
Version: internal.BetaVersion,
Kind: internal.AerospikeBackupKind,
},
{
Group: internal.Group,
Version: internal.BetaVersion,
Kind: internal.AerospikeRestoreKind,
},
appsv1.SchemeGroupVersion.WithKind(internal.STSKind),
appsv1.SchemeGroupVersion.WithKind(internal.DeployKind),
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
26 changes: 17 additions & 9 deletions pkg/internal/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,20 @@ 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"
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 All @@ -35,4 +40,7 @@ const (
ValidatingWebhookKind = "ValidatingWebhookConfiguration"
ClusterRoleKind = "ClusterRole"
ClusterRoleBindingKind = "ClusterRoleBinding"

Group = "asdb.aerospike.com"
BetaVersion = "v1beta1"
)
Loading