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

[LFX-Q2]: Enhance/improve chaos center code base and redesign chaos workflow apis #3970

Closed
imrajdas opened this issue May 9, 2023 · 15 comments
Labels
LFX-MENTORSHIP Linux Foundation Mentor ship Issue

Comments

@imrajdas
Copy link
Member

imrajdas commented May 9, 2023

This task is divided into multiple subtasks.

  • Refactor the chaos-workflow pkg into interfaces and split the chaos-workflow and chaos-workflow run into separate pkg

  • Resolve security vulnerability and golangci-lints of chaos-center backend components (Graphql Server, Subscriber, Auth-Server)

  • Add unit test cases for chaos-center backend components

  • Refactor chaos-subscriber codebases and add interfaces for the functions

  • Currently, our users are facing difficulty to use chaos workflow graphql APIs, so, we need to redesign the chaos workflow and workflow run APIs

Additional/Optional

Repository Ref:

Note:

  • Candidate should know Golang, Kubernetes, and backend development. It's okay if the individual is not familiar with litmuschaos.
@Swapnil-2502
Copy link

Is it too late to start reading documentation to understand the project and apply for LFX mentorship under your organisation.

@imrajdas
Copy link
Member Author

@Swapnil-2502 - please send your proposal to lfx. We will review

@money8203
Copy link

Hey @imrajdas,

I'd love to work on this project as a part of LFX mentorship . As I am learning go, I believe this project will be a great opportunity for me to apply my skills and gain hands-on experience. Looking forward to contributing to the project's success.

@maheshkasabe
Copy link

Hello @imrajdas

I would really love to work on this issue as it perfectly aligns with my current Technical skills as i'm quite familiar with Kubernetes and Backend Developement, and i would really love to take this issue hands-on and work around it! will you mention any of IRC channels so i can explain and learn more about this issue ?

@SD-13
Copy link

SD-13 commented May 16, 2023

@imrajdas Just curious about what are the difficulties users are facing for Graphql API that can be resolved by REST API. Can you please shed some light on this or refer to any discussion about this? Thanks!

@achiverram28
Copy link

achiverram28 commented May 17, 2023

@imrajdas Hello mentor for the LFX Mentorship program -> CNCF - LitmusChaos: Migrate chaos workflow api from graphql to rest and improve chaos center code
I am Ram Samarth B B , a 2nd year undergrad pursuing my BTech in Computer Science and Engineering at Indian Institute of Information Technology Kottayam . I am deep DevOps and Cloud Native enthusiast , especially Kubernetes and have been working on learning it in deep . I came across this project in LFX Mentorship . I would really like to learn the working of the litmus , and would like to contribute to this project under this mentorship . I have a strong hold on Kubernetes , configuration , API development, Open Application model . Please help me how to contribute to this project . I would give my best to work on it.I am also working on the setting up of the project . I want the guidance of the mentor @imrajdas
. Please help me out

@imrajdas imrajdas changed the title [LFX-Q2]: Migrate chaos workflow api from graphql to rest and improve chaos center code base [LFX-Q2]: Enhanced/improved chaos center code base and design chaos workflow rest apis May 20, 2023
@imrajdas
Copy link
Member Author

Hi applicants, there is a slight change in this issue.

This issue will focus more on the chaos center code base enhancement than the chaos workflow API changes.

@imrajdas imrajdas changed the title [LFX-Q2]: Enhanced/improved chaos center code base and design chaos workflow rest apis [LFX-Q2]: Enhanced/improved chaos center code base and redesign chaos workflow rest apis May 20, 2023
@imrajdas imrajdas changed the title [LFX-Q2]: Enhanced/improved chaos center code base and redesign chaos workflow rest apis [LFX-Q2]: Enhanced/improved chaos center code base and redesign chaos workflow apis May 20, 2023
@imrajdas
Copy link
Member Author

imrajdas commented May 20, 2023

Hi all, Please submit your applications to LFX portal before the deadline

@achiverram28
Copy link

Hi applicants, there is a slight change in this issue.

This issue will focus more on the chaos center code base enhancement than the chaos workflow API changes.

Sure , now worries

@achiverram28
Copy link

Hi all, Please submit your applications to LFX portal before the deadline

Have submitted

@imrajdas imrajdas changed the title [LFX-Q2]: Enhanced/improved chaos center code base and redesign chaos workflow apis [LFX-Q2]: Enhance/improve chaos center code base and redesign chaos workflow apis May 20, 2023
@Aadeesh11
Copy link

Hi all, Please submit your applications to LFX portal before the deadline

Submitted! Setting up the project!

@SohamRatnaparkhi
Copy link
Contributor

SohamRatnaparkhi commented May 21, 2023

Hi applicants, there is a slight change in this issue.

This issue will focus more on the chaos center code base enhancement than the chaos workflow API changes.

Thank you @imrajdas for giving this update.
After successfully setting up the project, I have updated my proposal, and submitted it on LFX website.

I am extremely enthusiastic about the opportunity to learn and contribute to LitmusChaos. I am confident that my skills and experience make me a strong candidate to make meaningful contributions to this project.

@prajak002
Copy link

Hi @imrajdas I am Prajak Sen, a pre-final year student at IEM Kolkata, India. i have 3+ years of experiences in backend development , i have worked with Go and Kubernetes in my past days, i have followed the code base of litmus chaos portal , and seen the architectural workflow of chaos and the pkg underlying the graphql-server directory of the reference repository.

  1. spliting the chaos-workflow and chaos-workflow run into separate pkg

here we can split the chaos-workflow into seperate interfaces in this manner :-

modified chaos_workflow.go should be looked like this

// File: litmus-portal/graphql-server/pkg/chaos-workflow/chaos_workflow.go

package workflow

type WorkflowClient interface {
	CreateWorkflow() error
	GetWorkflowByID(id string) (*Workflow, error)
	// Other methods...
}

type ExperimentClient interface {
	CreateExperiment() error
	GetExperimentByID(id string) (*Experiment, error)
	// Other methods...
}

type WorkflowTemplateClient interface {
	CreateTemplate() error
	GetTemplateByID(id string) (*WorkflowTemplate, error)
	// Other methods...
}

type ChaosWorkflow struct {
	WorkflowClient
	ExperimentClient
	WorkflowTemplateClient
	// Other fields...
}

// Other struct definitions and implementations...

again we can build chaos-workflow_run.go in this way to run the workflow instance

// File: litmus-portal/graphql-server/pkg/chaos-workflow-run/chaos_workflow_run.go

package workflowrun

import "litmus-portal/graphql-server/pkg/chaos-workflow"

type WorkflowRunManager interface {
	RunWorkflow(workflowID string) error
	GetWorkflowRunStatus(runID string) (string, error)
	// Other methods...
}

type ChaosWorkflowRun struct {
	WorkflowRunManager
	// Other fields...
}

// Other struct definitions and implementations...

  1. redesigning the chaos workflow and workflow run APIs

to build a strongly-typed schema for the chaos workflow graphql api , we can design this schema in this way :-

type Workflow {
  id: ID!
  name: String!
  description: String!
  templateId: ID!
  parameters: Parameters!
}

type Parameters {
  param1: String!
  param2: String!
  # Add more parameters as needed
}

input CreateWorkflowInput {
  name: String!
  description: String!
  templateId: ID!
  parameters: ParametersInput!
}

input ParametersInput {
  param1: String!
  param2: String!
  # Add more parameters as needed
}

type Query {
  workflow(id: ID!): Workflow
  # Add more queries as needed
}

type Mutation {
  createWorkflow(input: CreateWorkflowInput!): Workflow
  updateWorkflow(id: ID!, input: CreateWorkflowInput!): Workflow
  deleteWorkflow(id: ID!): ID
  # Add more mutations as needed
}

here, a Workflow type with its properties such as id, name, description, templateId, and parameters. The Parameters type represents the set of parameters for a workflow.

The CreateWorkflowInput input type is used for creating a new workflow, while the ParametersInput input type is used for specifying the parameters.

The Query type provides a single query field workflow to retrieve a specific workflow by its ID. You can extend this type with more queries based on your requirements.

The Mutation type defines mutation fields to create, update, and delete workflows. You can add more mutation fields as needed to fulfill other operations.

  1. Refactor chaos-subscriber codebases and add interfaces for the functions

When refactoring the chaos-subscriber codebase and adding interfaces for the functions in a Kubernetes-based environment, we need to consider the specific requirements and interactions with Kubernetes resources.

we may implement in this way 🥇

package main

import (
	"fmt"
	"log"
	"os"

	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/kubernetes"
	"k8s.io/client-go/tools/clientcmd"
)

// Interface for Kubernetes resource operations
type KubernetesClient interface {
	GetPods(namespace string) ([]corev1.Pod, error)
}

// Implementation of KubernetesClient interface using the official Kubernetes client library
type OfficialKubernetesClient struct {
	clientset *kubernetes.Clientset
}

func NewOfficialKubernetesClient(kubeconfigPath string) (*OfficialKubernetesClient, error) {
	config, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath)
	if err != nil {
		return nil, err
	}

	clientset, err := kubernetes.NewForConfig(config)
	if err != nil {
		return nil, err
	}

	return &OfficialKubernetesClient{
		clientset: clientset,
	}, nil
}

func (c *OfficialKubernetesClient) GetPods(namespace string) ([]corev1.Pod, error) {
	pods, err := c.clientset.CoreV1().Pods(namespace).List(metav1.ListOptions{})
	if err != nil {
		return nil, err
	}

	return pods.Items, nil
}

// Example usage
func main() {
	kubeconfigPath := os.Getenv("KUBECONFIG")
	if kubeconfigPath == "" {
		log.Fatal("KUBECONFIG environment variable is not set")
	}

	// Create an instance of the Kubernetes client
	client, err := NewOfficialKubernetesClient(kubeconfigPath)
	if err != nil {
		log.Fatalf("Failed to create Kubernetes client: %v", err)
	}

	// Get pods from a specific namespace
	pods, err := client.GetPods("default")
	if err != nil {
		log.Fatalf("Failed to get pods: %v", err)
	}

	// Process the pods
	for _, pod := range pods {
		fmt.Printf("Pod: %s\n", pod.Name)
		// Perform your desired operations with the pod
	}
}

we define the KubernetesClient interface that represents the operations we want to perform on Kubernetes resources. The OfficialKubernetesClient struct implements the interface using the official Kubernetes client library for Go.

The NewOfficialKubernetesClient function creates an instance of OfficialKubernetesClient by initializing the Kubernetes client using the provided kubeconfig file path.

The GetPods method of OfficialKubernetesClient retrieves a list of pods from the specified namespace using the Kubernetes client library.

In the main function, we create an instance of OfficialKubernetesClient and demonstrate how to use the GetPods method to retrieve and process pods from the "default" namespace.

Make sure to have the necessary dependencies, such as the Kubernetes client Go library (k8s.io/client-go), imported into your project.

Set the KUBECONFIG environment variable with the path to your kubeconfig file before running the program.

  1. previous works

i have also tried to modify the center code base enhancement i.e. "Enhance/Upgrade chaos operator and chaos exporter module" and here this is my brief idea of implementing this enhancement :https://github.com/litmuschaos/litmus/issues/3969

so that will be fine tuned

I would love to be a part of this beautiful community and looking forward to a positive reply
Thank you :)

@imrajdas
Copy link
Member Author

Hi all, Today(May 23, 5:00 PM PDT) is the last day to submit your proposal to the LFX portal

Apply link- https://mentorship.lfx.linuxfoundation.org/project/983193ea-9cca-405f-baa5-e6ade4df1ba2

@imrajdas
Copy link
Member Author

imrajdas commented Jun 1, 2023

Hi All, We have finalized the LFX mentee. We participate in LFX every 3 months. Please apply it for next term in case you didn't get selected.

Please feel free to contribute to the LitmusChaos project or join the monthly community call to learn about the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LFX-MENTORSHIP Linux Foundation Mentor ship Issue
Projects
None yet
Development

No branches or pull requests

10 participants