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

Export the client utils for external integrations #889

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Praveenrajmani
Copy link
Collaborator

@Praveenrajmani Praveenrajmani commented Dec 26, 2023

This will be used to integrate DirectPV externally and provides common usage of functions

For example,

package main

import (
	"context"
	"fmt"
	"os"
	"path/filepath"

	"github.com/minio/directpv/pkg/client"
	"k8s.io/client-go/rest"
	"k8s.io/client-go/tools/clientcmd"
)

const (
	MaxThreadCount = 200
)

func getKubeConfig() (*rest.Config, error) {
	home, err := os.UserHomeDir()
	if err != nil {
		return nil, err
	}
	kubeConfig := filepath.Join(home, ".kube", "config")
	config, err := clientcmd.BuildConfigFromFlags("", kubeConfig)
	if err != nil {
		if config, err = rest.InClusterConfig(); err != nil {
			return nil, err
		}
	}
	config.QPS = float32(MaxThreadCount / 2)
	config.Burst = MaxThreadCount
	return config, nil
}

func main() {
	kubeConfig, err := getKubeConfig()
	if err != nil {
		fmt.Printf("%s: Could not connect to kubernetes. %s=%s\n", "Error", "KUBECONFIG", kubeConfig)
		os.Exit(1)
	}
	adminClient, err := admin.NewClient(kubeConfig)
	if err != nil {
		log.Fatalf("unable to initialize client; %v", err)
	}
	drives, err := adminClient.NewDriveLister().Get(context.Background())
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	for _, drive := range drives {
		fmt.Printf("\n DeviceName: %v", drive.GetDriveName())
		fmt.Printf("\n Node: %v", drive.GetNodeID())
		fmt.Printf("\n Make: %v", drive.Status.Make)
		fmt.Println()
	}
}

and with the following line in go.mod

replace github.com/minio/directpv => ../directpv

after merging, we can use the master's commit id in the go.mod

require (
    github.com/minio/directpv <commit-id>
)

also checkout the examples in pkg/admin/examples/

@Praveenrajmani Praveenrajmani force-pushed the clientutils branch 2 times, most recently from 4057edb to 85fc6ed Compare December 26, 2023 10:54
@Praveenrajmani Praveenrajmani changed the title Expose the client utils for external integrations Export the client utils for external integrations Dec 26, 2023
@Praveenrajmani Praveenrajmani force-pushed the clientutils branch 2 times, most recently from 55c8fb6 to fd0d1cd Compare December 26, 2023 13:34
@Praveenrajmani Praveenrajmani marked this pull request as draft December 27, 2023 15:27
@Praveenrajmani Praveenrajmani marked this pull request as ready for review January 18, 2024 12:04
prakashsvmx
prakashsvmx previously approved these changes Jan 22, 2024
dvaldivia
dvaldivia previously approved these changes Jan 26, 2024
Copy link

@dvaldivia dvaldivia left a comment

Choose a reason for hiding this comment

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

LGTM

@Praveenrajmani
Copy link
Collaborator Author

dvaldivia
dvaldivia previously approved these changes Feb 20, 2024
Copy link

@dvaldivia dvaldivia left a comment

Choose a reason for hiding this comment

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

LGTM

prakashsvmx
prakashsvmx previously approved these changes Mar 19, 2024
Copy link
Member

@prakashsvmx prakashsvmx left a comment

Choose a reason for hiding this comment

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

Tested the basic functions. LGTM 👍

@Praveenrajmani
Copy link
Collaborator Author

Have made some changes to add appropriate return types for the admin functions. PTAL @balamurugana @prakashsvmx @dvaldivia

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants