-
Notifications
You must be signed in to change notification settings - Fork 5
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
[POA-2609] Add k8s and CRI sub-modules and function interfaces #66
Open
mudit-postman
wants to merge
9
commits into
main
Choose a base branch
from
mudit/poa-2609
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For testing I have created a project which calls all the functions in a flow.
Test code `main.go`package main
import (
"fmt"
"os"
"test-proj/cri_apis"
"test-proj/kube_apis"
"github.com/postmanlabs/postman-insights-agent/printer"
)
func k8s_funcs(podName string) (string, error) {
// Initialize KubeClient
kubeClient, err := kube_apis.NewKubeClient()
if err != nil {
return "", fmt.Errorf("failed to create KubeClient: %v", err)
}
defer kubeClient.TearDown()
// GetPodContainerImages
podImages, err := kubeClient.GetPodContainerImages(podName)
if err != nil {
return "", fmt.Errorf("failed to get pod container images: %v", err)
}
printer.Infof("Pod Container Images: %v\n", podImages)
// GetMainContainerUUID
containerUUID, err := kubeClient.GetMainContainerUUID(podName)
if err != nil {
return "", fmt.Errorf("failed to get main container UUID: %v", err)
}
printer.Infof("Main Container UUID: %s\n", containerUUID)
// GetPodsInNode
podNames, err := kubeClient.GetPodsInNode(kubeClient.AgentNode)
if err != nil {
return containerUUID, fmt.Errorf("failed to get pods in node: %v", err)
}
printer.Infof("Pods in Node: %v\n", podNames)
// GetPodStatus
podStatus, err := kubeClient.GetPodStatus(podName)
if err != nil {
return containerUUID, fmt.Errorf("failed to get pod status: %v", err)
}
printer.Infof("Pod Status: %s\n", podStatus)
return containerUUID, nil
}
func cri_funcs(containerUUID string) error {
// Initialize CriClient
criClient, err := cri_apis.NewCRIClient("")
if err != nil {
return fmt.Errorf("failed to create CriClient: %v", err)
}
// GetNetworkNamespace
networkNamespace, err := criClient.GetNetworkNamespace(containerUUID)
if err != nil {
return fmt.Errorf("failed to get network namespace: %v", err)
}
printer.Infof("Network Namespace: %s\n", networkNamespace)
// GetEnvVars
envVars, err := criClient.GetEnvVars(containerUUID)
if err != nil {
return fmt.Errorf("failed to get environment variables: %v", err)
}
printer.Infof("Environment Variables: %v\n", envVars)
return nil
}
func main() {
// Check if args are provided
if len(os.Args) < 2 {
printer.Errorln("Pod name not provided")
return
}
podName := os.Args[1]
// Call k8s_funcs
containerUUID, err := k8s_funcs(podName)
if err != nil {
printer.Errorf("Error from k8s_funcs: %v\n", err)
}
// Call cri_funcs
if containerUUID == "" {
printer.Infoln("Container UUID not found, exiting...")
return
}
err = cri_funcs(containerUUID)
if err != nil {
printer.Errorf("Error from cri_funcs: %v\n", err)
}
} |
mgritter
approved these changes
Feb 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a good start, I would consider putting these in a subdirectory.
In this PR, we have implemented K8s API functions for interaction with K8s from inside the container Functions implemented: * NewKubeClient: Initalize the kube client, create a clientset object and open a event watcher for events. * TearDown: Function to be called on program shutdown to close event watcher. * GetPodContainerImages: Will be used to check if agent is running as sidecar * GetMainContainerUUID: Fetches container UUID, used by CRI module to inspect container * GetPodsInNode: Get the list of pods running in the node agent is running. Will be used to get list of existing pods on agent start up * GetPodStatus: Get the health status, used by the go routine to track the health of pods where apidump is running.
…into mudit/poa-2609
…hts-agent into mudit/poa-2609
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In this PR, we created basic interfaces and functions in K8s and CRI modules.
K8s Functions:
CRI Functions:
Note: This PR have some other functions which were created initially but later removed in implementation PRs.