Skip to content

Instantly share code, notes, and snippets.

@sarthaksarthak9
Last active August 10, 2023 15:20
Show Gist options
  • Save sarthaksarthak9/21af2dd3f04e7ac47dcf3e818ca96968 to your computer and use it in GitHub Desktop.
Save sarthaksarthak9/21af2dd3f04e7ac47dcf3e818ca96968 to your computer and use it in GitHub Desktop.
LFX'23 PROJECT PROPOSAL (KubeEdge)

LFX'23 PROJECT PROPOSAL (KubeEdge)

Support latest kubeedge demo in killercoda-scenarios

🚀 About Me

Name : Sarthak Negi

Github : sarthaksarthak9

Email : sarthaknegi908@gmail.com

Location : Delhi,India

Timezone : IST(UTC +5:30)

Portfolio/blog : https://sarthak007.hashnode.dev/

Abstract

KubeEdge is an open source project that extends Kubernetes to the edge. It enables developers to deploy and manage applications on edge devices, such as IoT devices and gateways. killercoda is an interactive learning platform that allows developers to learn and practice cloud native technologies.

This project will update the KubeEdge tutorial on killercoda to support the latest version of KubeEdge. The updated tutorial will provide a hands-on experience of deploying KubeEdge on a local development environment. It will also include examples of running cloud native applications on edge devices.

The expected outcome of this project is to provide developers with a comprehensive learning experience for KubeEdge. The updated tutorial will make it easier for developers to get started with KubeEdge and to deploy cloud native applications on edge devices.

Related issue: kubeedge/killercoda-scenarios#8

Implementation

Function to fetch the list of KubeEdge examples from a YAML file

  1. The url variable holds the URL of the YAML file that contains the list of KubeEdge examples. This URL points to the raw content of the file on GitHub.

  2. The http.Get function is used to make an HTTP GET request to the specified url. If there's an error during the request, such as a network issue or invalid URL, the function immediately returns the error along with a nil slice.

func getKubeEdgeExamples() ([]Example, error) {
	url := "https://raw.githubusercontent.com/kubeedge/examples/master/list.yaml"
	response, err := http.Get(url)
	if err != nil {
		return nil, err
	}
  1. The status code of the HTTP response is checked. If the status code is not http.StatusOK (200), an error is returned with a descriptive message indicating the failure to fetch the examples.

  2. The YAML parsing library (github.com/ghodss/yaml) is used to unmarshal (parse) the content of the YAML data into the kubeedgeExamples slice.

  3. At each step where an error can occur (response body closing, status code check, response reading, YAML parsing), error checks are performed. If an error occurs at any point, the function returns the error along with a nil slice.

defer response.Body.Close()

	if response.StatusCode != http.StatusOK {
		return nil, fmt.Errorf("Failed to get KubeEdge examples: %s", response.Status)
	}

	body, err := ioutil.ReadAll(response.Body)
	if err != nil {
		return nil, err
	}

	var kubeedgeExamples []Example
	err = yaml.Unmarshal(body, &kubeedgeExamples) // Use the YAML parsing library
	if err != nil {
		return nil, err
	}

	return kubeedgeExamples, nil
}

Function to update the killercoda-scenarios with KubeEdge examples

  1. The function checks if the directory specified by killercodaScenariosDir already exists using os.Stat and the os.IsNotExist function. If the directory does not exist, an error of type os.PathError with the Err field set to syscall.ENOENT is returned, indicating that the path does not exist.

  2. If the directory does not exist (as indicated by the error returned by os.IsNotExist), the function attempts to create the directory using os.Mkdir.

func updateKillercodaScenarios(kubeedgeExamples []Example) error {
	killercodaScenariosDir := "killercoda-scenarios"
	if _, err := os.Stat(killercodaScenariosDir); os.IsNotExist(err) {
		err := os.Mkdir(killercodaScenariosDir, 0755)
		if err != nil {
			return err
		}
	}
  1. An HTTP GET request is made to download the content of the example from the provided URL. If there's an error during the request, such as network issues or incorrect URL, the function immediately returns the error.

  2. An output file is created in the killercodaScenariosDir with the extracted name. If an error occurs during file creation (e.g., insufficient permissions or file already exists), the function immediately returns the error.

  3. At each step where an error can occur (HTTP request, file creation, content copying), error checks are performed. If an error occurs at any point, the function returns the error, indicating a failure in copying the example.

	for _, example := range kubeedgeExamples {
		name := example.Name
		url := example.URL
		filename := filepath.Join(killercodaScenariosDir, name)

		response, err := http.Get(url)
		if err != nil {
			return err
		}
		defer response.Body.Close()

		outFile, err := os.Create(filename)
		if err != nil {
			return err
		}
		defer outFile.Close()

		_, err = io.Copy(outFile, response.Body)
		if err != nil {
			return err
		}
	}

	return nil
}


Timeline

  • Week 1:

    1. Research KubeEdge and killercoda-scenarios.
    2. Understand the requirements for the integration.
    3. Create a plan for the integration and discuss with mentors.
  • Week 2 - Week 4:

    1. Implement the code for fetching the list of KubeEdge examples.
    2. Implement the code for updating the killercoda-scenarios project to include the KubeEdge examples.
    3. Test the code.
  • Week 5 - Week 7:

    1. Improve the documentation for the integration.
    2. Create a demo of the integration.
    3. Mid-Term Evalualution and get feedback from users.
  • Weeks 8-10:

    1. Fix any bugs that were found in the demo.
    2. Add new features to the integration.
    3. Make the integration more user-friendly.
  • Weeks 11-12:

    1. Documentation of the project.

I have only listed down the potential priority and focus tasks for each week in the above timeline, In addition to that my work in each week would be a blend of the following :

  • Breaking down issues into smaller modular tasks
  • Interacting and getting feedback from mentors
  • Team meetings
  • Writing blog post sharing my progress and LFX experience along the way

Why I am interested in working on this project :

I am interested in working on this project and KubeEdge because it presents an exciting opportunity to apply my skills in integrating the latest KubeEdge demos into killercoda-scenarios. I believe that by integrating the demos into killercoda-scenarios, developers will be able to run the demos with just a few clicks. This will make it much easier to get started with KubeEdge, and it will also help to ensure that the demos are always up-to-date.. Additionally, I am interested in working with KubeEdge because it is a well-established project with a strong community and this mentorship offers me a great oppurtunity to make a meaningful contribution to the KubeEdge ecosystem.

Commitments

There is no conflict of interest in the coding phase as of now and I don't plan to have any other commitment during the period and I will dedicate my fall to this project. If there will be any sudden changes in the university schedule, I will discuss with the mentors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment