Skip to content

Commit

Permalink
Incorporate requested changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwalantmodi05 committed Nov 14, 2024
1 parent a56c011 commit 83b013f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 81 deletions.
18 changes: 11 additions & 7 deletions cmd/collectinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
84 changes: 21 additions & 63 deletions pkg/collectinfo/collectinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const (
aerospikeRestoreName = "test-aerorestore"
pdbName = "test-pdb"
cmName = "test-cm"
rsName = "test-rs"
)

var (
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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())
}
19 changes: 9 additions & 10 deletions pkg/collectinfo/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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),
Expand Down
4 changes: 3 additions & 1 deletion pkg/internal/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const (
// Namespace scope resources
PodKind = "Pod"
STSKind = "StatefulSet"
RSKind = "ReplicaSet"
DeployKind = "Deployment"
ServiceAccountKind = "ServiceAccount"
ServiceKind = "Service"
Expand All @@ -41,4 +40,7 @@ const (
ValidatingWebhookKind = "ValidatingWebhookConfiguration"
ClusterRoleKind = "ClusterRole"
ClusterRoleBindingKind = "ClusterRoleBinding"

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

0 comments on commit 83b013f

Please sign in to comment.