pods

package
v0.0.61 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package pods is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHosts

func GetHosts()

Types

type IToolsK8S

type IToolsK8S interface {
	GetPodHosts(ctx context.Context, ctxLogger *builder.Context, namespace string) ([]string, error)
}

IToolsK8S define las operaciones del paquete k8s que pueden ser usadas o simuladas por otros componentes.

func New

func New(mock IToolsK8S) IToolsK8S

New crea una nueva herramienta para consultar recursos de Kubernetes. Si se proporciona un mock, las llamadas se delegan a ese objeto.

type MockIToolsK8S

type MockIToolsK8S struct {
	// contains filtered or unexported fields
}

MockIToolsK8S is a mock of IToolsK8S interface.

func NewMockIToolsK8S

func NewMockIToolsK8S(ctrl *gomock.Controller) *MockIToolsK8S

NewMockIToolsK8S creates a new mock instance.

func (*MockIToolsK8S) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockIToolsK8S) GetPodHosts

func (m *MockIToolsK8S) GetPodHosts(ctx context.Context, ctxLogger *builder.Context, namespace string) ([]string, error)

GetPodHosts mocks base method.

type MockIToolsK8SMockRecorder

type MockIToolsK8SMockRecorder struct {
	// contains filtered or unexported fields
}

MockIToolsK8SMockRecorder is the mock recorder for MockIToolsK8S.

func (*MockIToolsK8SMockRecorder) GetPodHosts

func (mr *MockIToolsK8SMockRecorder) GetPodHosts(ctx, ctxLogger, namespace interface{}) *gomock.Call

GetPodHosts indicates an expected call of GetPodHosts.

type ToolsK8S

type ToolsK8S struct {
	// contains filtered or unexported fields
}

ToolsK8S implementa el acceso a Kubernetes y opcionalmente delega en un doble de prueba.

func (*ToolsK8S) GetPodHosts

func (t *ToolsK8S) GetPodHosts(ctx context.Context, ctxLogger *builder.Context, namespace string) ([]string, error)

GetPodHosts obtains the IPs of Running and Ready pods selected by the configured Kubernetes Service in the provided namespace.

Example usage with a Gin server prepared for testing:

type PodHostDiscovery interface {
	GetPodHosts(ctx context.Context, ctxLogger *builder.Context, namespace string) ([]string, error)
}

type RefreshHandler struct {
	discovery PodHostDiscovery
}

func NewRefreshHandler(discovery PodHostDiscovery) *RefreshHandler {
	return &RefreshHandler{discovery: discovery}
}

func (h *RefreshHandler) Register(api *gin.RouterGroup) {
	api.GET("/refresh/hosts", h.GetHosts)
}

func (h *RefreshHandler) GetHosts(c *gin.Context) {
	ctx := c.Request.Context()
	ctxLogger := builder.New(ctx)
	namespace := viper.GetString("app.namespace")

	hosts, err := h.discovery.GetPodHosts(ctx, ctxLogger, namespace)
	if err != nil {
		c.JSON(500, gin.H{"error": err.Error()})
		return
	}

	serverGin.SetHostsRefresh(hosts...)
	c.JSON(200, gin.H{"hosts": hosts})
}

Production setup:

srv, err := serverGin.CreateApp()
if err != nil {
	panic(err)
}

api := serverGin.GetRoute("/api/v1")
handler := NewRefreshHandler(pods.New(nil))
handler.Register(api)

serverGin.Start(srv)

Test setup:

type mockPodDiscovery struct{}

func (m *mockPodDiscovery) GetPodHosts(_ context.Context, _ *builder.Context, _ string) ([]string, error) {
	return []string{"10.0.0.10", "10.0.0.11"}, nil
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL