Collection of mini-programs demonstrating Kubernetes client-go usage.

Overview

Kubernetes client-go examples

Collection of mini-programs covering various client-go use cases. The intention (at least so far) is to test (more or less) fresh version of Go and packages against a few latest Kubernetes versions.

What tested at the moment:

  • go 1.17
  • k8s.io/client-go v0.23.1
  • Kubernetes v1.22.3

Setup

All examples expect minikube with at least two Kubernetes clusters - shared1 and shared2.

curl -sLS https://get.arkade.dev | sudo sh
arkade get minikube kubectl

minikube start --profile shared1
minikube start --profile shared2

Run

Oversimplified (for now):

cd <program>
go run main.go

TODO

  • Add assertions to mini-programs
  • Test different Kubernetes versions
  • Setup GitHub action(s)
Issues
  • Thoughts on a common lib repeated functions?

    Thoughts on a common lib repeated functions?

    This is done a lot

    home, err := os.UserHomeDir()
    if err != nil {
    	panic(err)
    }
    
    cfg, err := clientcmd.BuildConfigFromFlags("", path.Join(home, ".kube/config"))
    if err != nil {
    	panic(err.Error())
    }
    
    client := kubernetes.NewForConfigOrDie(cfg)
    desired := corev1.ConfigMap{
    	ObjectMeta: metav1.ObjectMeta{
    		Name:      name,
    		Namespace: namespace,
    	},
    	Data: map[string]string{"foo": "bar"},
    }
    

    Thoughts on a pkg/common or common/ or . I thin it will help better focus on the example that's trying to be displayed rather than the setup.

    opened by dylanhitt 3
  • Example for `retry.RetryOnConflict`

    Example for `retry.RetryOnConflict`

    The repository should include an example of retry.RetryOnConflict.

    Current implementation idea:

    Folder Name: retry-on-conflict General Flow:

    • Create pod - keep reference
    • UpdateStatus pod - ignore reference to emulate the object changing unexpectedly from either another controller or external source
    • Implement retry function. To display the use we could use a timer to demonstrate performing long running task to validate the status of an object. For instance sometimes when working with CRDs that create resources external to k8s, gathering status can take a significant amount of time. A very naive solution would be just using a flag and skipping fetch on the first try. Not quite sure, but a simple explanation would be better than a complex example. Maybe someone has some thoughts on how to emulate this situation easily.
    err := retry.RetryOnConflict(retry.DefaultRetry, func() error {
        pod, err := c.Pods("ns").Get(name, metav1.GetOptions{})
        if err != nil {
            return err
        }
        
        // emulate long running tasks to get current status with timers
        
        _, err = c.Pods("ns").UpdateStatus(pod)
    })
    

    I'd like to submit a PR for this as I recently hit this position in a custom controller. @iximiuz I'd like to hear thoughts.

    opened by dylanhitt 3
  • Using klog in the examples

    Using klog in the examples

    Thank you for the blogposts and for these snippets! I think it's very useful to see the timestamps in the examples that you have, I was wondering if you'd be ok if I submit a change replacing fmt.Printf with klog.Infof

    opened by mauriciopoppe 3
  • retry on conflict simple example imeplementation

    retry on conflict simple example imeplementation

    So far:

    I hope this is along the lines of what is expected.

    Adds:

    • simple display of retry on conflict. The current code will produce the following log
    [email protected] retry-on-conflict (retry-on-conflict %)]$ go run main.go 
    Successfully updated ConfigMap
    Operation cannot be fulfilled on configmaps "foobar": the object has been modified; please apply your changes to the latest version and try again
    Successfully updated ConfigMap
    Operation cannot be fulfilled on configmaps "foobar": the object has been modified; please apply your changes to the latest version and try again
    Successfully updated ConfigMap
    Operation cannot be fulfilled on configmaps "foobar": the object has been modified; please apply your changes to the latest version and try again
    Successfully updated ConfigMap
    Operation cannot be fulfilled on configmaps "foobar": the object has been modified; please apply your changes to the latest version and try again
    Successfully updated ConfigMap
    Operation cannot be fulfilled on configmaps "foobar": the object has been modified; please apply your changes to the latest version and try again
    

    I will add documentation on real world use cases/the nuances of the example in the readme. I will also be adding some docs about the function retryOnConflict itself and it's nuances.

    cheers

    opened by dylanhitt 2
  • fix typo in workqueue readme

    fix typo in workqueue readme

    Small typo


    By the way awesome project. I find myself want to reference back to client-go example I no longer have access to or can't find. Expect to see a bit more of me.

    Cheers!

    opened by dylanhitt 1
  • Fix label-selector example

    Fix label-selector example

    At present, the selector remains empty even after the sel.Add(req) call.

    fmt.Printf("%v", sel) prints empty string.

    This is because the mutated sel is not reveived and assigned to sel at the caller.

    note: the signature of sel.Add function is Add(r ...Requirement) Selector

    Signed-off-by: Nikhil Thomas [email protected]

    opened by nikhil-thomas 1
kubernetes Display Resource (CPU/Memory/Gpu/PodCount) Usage and Request and Limit.

kubectl resource-view A plugin to access Kubernetes resource requests, limits, and usage. Display Resource (CPU/Memory/Gpu/PodCount) Usage and Request

bryant-rh 8 Apr 22, 2022
Like Komodor, just mini [••]

Minikom - like Komodor, just mini [••] Congratulations for receiving Komodor home assignment! If you made it this far, it means we're curious, and wou

null 0 Dec 20, 2021
🥝 Mini ECS CLI Command 🥝

miniecs ?? miniecs is a CLI tool for AWS ECS. ?? Requirement go 1.17.x or later �Installation go install github.com/jedipunkz/[email protected] Usage $ m

Tomokazu HIRAI 1 Jan 17, 2022
Based on the electron Cross-platform Mini browser

Based on the electron Cross-platform Mini browser

池边树下 1 May 1, 2022
Mini file storage with Go (Golang)

#Microstorage This is my exercise of creating simple file storage with GoLang Purpose: store and manipulate with user`s images in my pet projects ##Ve

Danila Minustin 1 Mar 13, 2022
Fadvisor(FinOps Advisor) is a collection of exporters which collect cloud resource pricing and billing data guided by FinOps, insight cost allocation for containers and kubernetes resource

[TOC] Fadvisor: FinOps Advisor fadvisor(finops advisor) is used to solve the FinOps Observalibility, it can be integrated with Crane to help users to

Crane 21 Jun 8, 2022
Kubernetes OS Server - Kubernetes Extension API server exposing OS configuration like sysctl via Kubernetes API

KOSS is a Extension API Server which exposes OS properties and functionality using Kubernetes API, so it can be accessed using e.g. kubectl. At the moment this is highly experimental and only managing sysctl is supported. To make things actually usable, you must run KOSS binary as root on the machine you will be managing.

Mateusz Gozdek 3 May 19, 2021
An Easy to use Go framework for Kubernetes based on kubernetes/client-go

k8devel An Easy to use Go framework for Kubernetes based on kubernetes/client-go, see examples dir for a quick start. How to test it ? Download the mo

null 10 Mar 25, 2022
This manager helps handle the life cycle of your eBPF programs

eBPF Manager This repository implements a manager on top of Cilium's eBPF library. This declarative manager simplifies attaching and detaching eBPF pr

Datadog, Inc. 22 Jun 20, 2022
A library for writing backup programs in Golang

Barkup godoc.org/github.com/keighl/barkup Barkup is a library for backing things up. It provides tools for writing bare-bones backup programs in Go. T

Kyle Truscott 211 Jun 27, 2022
Simple tuning work for go programs in high concurrency scenarios.

go-program-tuning Simple tuning work for go programs in high concurrency scenarios. Installation Run the following command under your project: go get

Afeyer 3 Mar 15, 2022
CPU usage percentage is the ratio of the total time the CPU was active, to the elapsed time of the clock on your wall.

Docker-Kubernetes-Container-CPU-Utilization Implementing CPU Load goroutine requires the user to call the goroutine from the main file. go CPULoadCalc

Ishank Jain 1 Dec 15, 2021
Kube - A simple Kubernetes client, based on client-go

kube A simple Kubernetes client, based on client-go.

PengQi Shi 1 Jun 5, 2022
A collection of Go style guides

This is a collection of style guides for Go. Be sure to read about writing engineering guidelines before trying to adopt one of these wholesale. (For

Damian Gryski 821 Jun 20, 2022
⚔️ Web Hacker's Weapons / A collection of cool tools used by Web hackers. Happy hacking , Happy bug-hunting

A collection of cool tools used by Web hackers. Happy hacking , Happy bug-hunting Family project Table of Contents WHW-Tools Weapons Awesome Bookmarkl

HAHWUL 2k Jun 30, 2022
A collection of commands for work done on GitHub

gh_sugar A collection of commands for work done on GitHub command pr Create pull request. Usage of pr: -from string from branch -owner str

Masaya Nasu 3 Oct 19, 2021
K8s - A Collection of tools, hands-on walkthroughs with source code

The Ultimate Engineer Toolbox ?? ?? A Collection of tools, hands-on walkthroughs

null 0 Feb 14, 2022
Litmus helps Kubernetes SREs and developers practice chaos engineering in a Kubernetes native way.

Litmus Cloud-Native Chaos Engineering Read this in other languages. ???? ???? ???? ???? Overview Litmus is a toolset to do cloud-native chaos engineer

Litmus Chaos 3.1k Jun 30, 2022
KEDA is a Kubernetes-based Event Driven Autoscaling component. It provides event driven scale for any container running in Kubernetes

Kubernetes-based Event Driven Autoscaling KEDA allows for fine-grained autoscaling (including to/from zero) for event driven Kubernetes workloads. KED

KEDA 5.1k Jul 1, 2022