From 83b013ff16109308aea441303c5e9b4ff441330b Mon Sep 17 00:00:00 2001 From: Jwalant Modi Date: Thu, 14 Nov 2024 16:29:27 +0530 Subject: [PATCH] Incorporate requested changes. --- cmd/collectinfo.go | 18 ++++--- pkg/collectinfo/collectinfo_test.go | 84 ++++++++--------------------- pkg/collectinfo/resources.go | 19 ++++--- pkg/internal/constants.go | 4 +- 4 files changed, 44 insertions(+), 81 deletions(-) diff --git a/cmd/collectinfo.go b/cmd/collectinfo.go index 918b116..859390f 100644 --- a/cmd/collectinfo.go +++ b/cmd/collectinfo.go @@ -32,13 +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, deployments, persistentvolumeclaims, aerospikeclusters, aerospikebackupservices, -* aerospikebackups, aerospikerestores, configmaps, replicasets, poddisruptionbudgets, services, -* nodes, storageclasses, persistentvolumes 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) diff --git a/pkg/collectinfo/collectinfo_test.go b/pkg/collectinfo/collectinfo_test.go index 6959b9d..c210458 100644 --- a/pkg/collectinfo/collectinfo_test.go +++ b/pkg/collectinfo/collectinfo_test.go @@ -59,7 +59,6 @@ const ( aerospikeRestoreName = "test-aerorestore" pdbName = "test-pdb" cmName = "test-cm" - rsName = "test-rs" ) var ( @@ -107,8 +106,6 @@ var filesList = map[string]bool{ 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, @@ -251,85 +248,36 @@ var _ = Describe("collectInfo", func() { Expect(err).ToNot(HaveOccurred()) gvk := schema.GroupVersionKind{ - Group: "asdb.aerospike.com", + Group: internal.Group, Version: "v1", Kind: internal.AerospikeClusterKind, } - u := &unstructured.Unstructured{} - u.SetName(aerospikeClusterName) - u.SetNamespace(namespace) - u.SetGroupVersionKind(gvk) - - err = k8sClient.Create(context.TODO(), u) - Expect(err).ToNot(HaveOccurred()) + createUnstructuredObject(aerospikeClusterName, namespace, gvk) gvk = schema.GroupVersionKind{ - Group: "asdb.aerospike.com", - Version: "v1beta1", + Group: internal.Group, + Version: internal.BetaVersion, 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()) + createUnstructuredObject(aerospikeBackupServiceName, namespace, gvk) gvk = schema.GroupVersionKind{ - Group: "asdb.aerospike.com", - Version: "v1beta1", + Group: internal.Group, + Version: internal.BetaVersion, 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()) + createUnstructuredObject(aerospikeBackupName, namespace, gvk) gvk = schema.GroupVersionKind{ - Group: "asdb.aerospike.com", - Version: "v1beta1", + Group: internal.Group, + Version: internal.BetaVersion, 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()) + createUnstructuredObject(aerospikeRestoreName, namespace, gvk) maxUnavailable := intstr.FromInt32(1) pdb := &policyv1.PodDisruptionBudget{ @@ -425,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()) +} diff --git a/pkg/collectinfo/resources.go b/pkg/collectinfo/resources.go index 3273d34..e9585e8 100644 --- a/pkg/collectinfo/resources.go +++ b/pkg/collectinfo/resources.go @@ -16,13 +16,14 @@ 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 ( @@ -44,32 +45,30 @@ var ( internal.AerospikeRestoreKind: "aerospikerestores", internal.PodDisruptionBudgetKind: "poddisruptionbudgets", internal.ConfigMapKind: "configmaps", - internal.RSKind: "replicasets", } gvkListNSScoped = []schema.GroupVersionKind{ { - Group: "asdb.aerospike.com", + Group: internal.Group, Version: "v1", Kind: internal.AerospikeClusterKind, }, { - Group: "asdb.aerospike.com", - Version: "v1beta1", + Group: internal.Group, + Version: internal.BetaVersion, Kind: internal.AerospikeBackupServiceKind, }, { - Group: "asdb.aerospike.com", - Version: "v1beta1", + Group: internal.Group, + Version: internal.BetaVersion, Kind: internal.AerospikeBackupKind, }, { - Group: "asdb.aerospike.com", - Version: "v1beta1", + Group: internal.Group, + Version: internal.BetaVersion, 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), diff --git a/pkg/internal/constants.go b/pkg/internal/constants.go index 300de17..c701385 100644 --- a/pkg/internal/constants.go +++ b/pkg/internal/constants.go @@ -19,7 +19,6 @@ const ( // Namespace scope resources PodKind = "Pod" STSKind = "StatefulSet" - RSKind = "ReplicaSet" DeployKind = "Deployment" ServiceAccountKind = "ServiceAccount" ServiceKind = "Service" @@ -41,4 +40,7 @@ const ( ValidatingWebhookKind = "ValidatingWebhookConfiguration" ClusterRoleKind = "ClusterRole" ClusterRoleBindingKind = "ClusterRoleBinding" + + Group = "asdb.aerospike.com" + BetaVersion = "v1beta1" )