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

comments for K8 describe package #294

Merged
merged 8 commits into from
Apr 13, 2023
Merged
Changes from 6 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
19 changes: 12 additions & 7 deletions utils/kubernetes/describe/describe.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package describe

// describe package provides a way to describe Kubernetes objects for the kubernetes Api

import (
meshkitkube "github.com/layer5io/meshkit/utils/kubernetes"
appsv1 "k8s.io/api/apps/v1"
Expand All @@ -17,13 +19,14 @@ import (

// DescriberOptions give control of which kubernetes object to describe.
type DescriberOptions struct {
Name string // Name of the kubernetes obj
Namespace string // Namespace of the kubernetes obj
ShowEvents bool
ChunkSize int64
Type DescribeType
Name string // Name of the kubernetes obj
Namespace string // Namespace of the kubernetes obj
ShowEvents bool // A boolean flag indicating whether to show events associated with the Kubernetes object or not.
ChunkSize int64 //Size of the chunk in which the Kubernetes object's output is written.
Type DescribeType //an integer value that represents the Kubernetes source that needs to be described
}

// DescribeType is an integer value that represents the Kubernetes resource that needs to be described.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a blank at the beginning, CI cannot run succeed. So, please remove it.

type DescribeType int

const (
Expand Down Expand Up @@ -57,6 +60,7 @@ const (
EndpointSlice
)

// The ResourceMap variable contains the GroupKind information of all the Kubernetes resources that can be described.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here.

var ResourceMap = map[DescribeType]schema.GroupKind{
Pod: {Group: corev1.GroupName, Kind: "Pod"},
Deployment: {Group: appsv1.GroupName, Kind: "Deployment"},
Expand Down Expand Up @@ -88,22 +92,23 @@ var ResourceMap = map[DescribeType]schema.GroupKind{
EndpointSlice: {Group: discoveryv1.GroupName, Kind: "EndpointSlice"},
}

// The Describe() function takes a meshkitkube.Client object and a DescriberOptions object as input.
// And it returns the description of the specified Kubernetes resource as a string.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want me to remove the comments or the spaces in between the comments ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The space at the second comment

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have removed the spaces

func Describe(client *meshkitkube.Client, options DescriberOptions) (string, error) {
// getting schema.GroupKind from Resource map
kind := ResourceMap[options.Type]
describer, ok := describe.DescriberFor(kind, &client.RestConfig)
if !ok {
return "", ErrGetDescriberFunc()
}

describerSetting := describe.DescriberSettings{
ShowEvents: options.ShowEvents,
ChunkSize: options.ChunkSize,
}
//calls a corresponding "describer" function to retrieve the description of the specified Kubernetes resource
output, err := describer.Describe(options.Namespace, options.Name, describerSetting)
if err != nil {
return "", err
}

return output, nil
}