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

Import index funcs from Tink #268

Merged
merged 1 commit into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 4 additions & 57 deletions client/kubernetes/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/tinkerbell/tink/pkg/apis/core/v1alpha1"
"github.com/tinkerbell/tink/pkg/controllers"
"k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
Expand Down Expand Up @@ -53,17 +54,17 @@ func NewCluster(config *rest.Config) (cluster.Cluster, error) {
{
&v1alpha1.Workflow{},
WorkflowWorkerNonTerminalStateIndex,
workflowWorkerNonTerminalStateIndexFunc,
controllers.WorkflowWorkerNonTerminalStateIndexFunc,
},
{
&v1alpha1.Hardware{},
HardwareIPAddrIndex,
hardwareIPIndexFunc,
controllers.HardwareIPIndexFunc,
},
{
&v1alpha1.Hardware{},
HardwareMACAddrIndex,
hardwareMacIndexFunc,
controllers.HardwareMacIndexFunc,
},
}
for _, indexer := range indexers {
Expand All @@ -79,57 +80,3 @@ func NewCluster(config *rest.Config) (cluster.Cluster, error) {

return c, nil
}

// TODO micahhausler: make the following index functions public in tinkerbell/tink import from there

// workflowWorkerNonTerminalStateIndexFunc func indexes workflow by worker for non terminal workflows.
func workflowWorkerNonTerminalStateIndexFunc(obj client.Object) []string {
wf, ok := obj.(*v1alpha1.Workflow)
if !ok {
return nil
}

resp := []string{}
if !(wf.Status.State == v1alpha1.WorkflowStateRunning || wf.Status.State == v1alpha1.WorkflowStatePending) {
return resp
}
for _, task := range wf.Status.Tasks {
if task.WorkerAddr != "" {
resp = append(resp, task.WorkerAddr)
}
}

return resp
}

// hardwareMacIndexFunc returns a list of mac addresses from a hardware.
func hardwareMacIndexFunc(obj client.Object) []string {
hw, ok := obj.(*v1alpha1.Hardware)
if !ok {
return nil
}
resp := []string{}
for _, iface := range hw.Spec.Interfaces {
if iface.DHCP != nil && iface.DHCP.MAC != "" {
resp = append(resp, iface.DHCP.MAC)
}
}

return resp
}

// hardwareIPIndexFunc returns a list of mac addresses from a hardware.
func hardwareIPIndexFunc(obj client.Object) []string {
hw, ok := obj.(*v1alpha1.Hardware)
if !ok {
return nil
}
resp := []string{}
for _, iface := range hw.Spec.Interfaces {
if iface.DHCP != nil && iface.DHCP.IP != nil && iface.DHCP.IP.Address != "" {
resp = append(resp, iface.DHCP.IP.Address)
}
}

return resp
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/davecgh/go-spew v1.1.1
github.com/equinix-labs/otel-init-go v0.0.5
github.com/gammazero/workerpool v0.0.0-20200311205957-7b00833861c6
github.com/go-logr/logr v1.2.2
github.com/go-logr/logr v1.2.3
github.com/go-logr/zapr v1.2.2
github.com/golang/mock v1.6.0
github.com/golangci/golangci-lint v1.45.2
Expand All @@ -24,7 +24,7 @@ require (
github.com/sebest/xff v0.0.0-20160910043805-6c115e0ffa35
github.com/stretchr/testify v1.7.1
github.com/tinkerbell/ipxedust v0.0.0-20220406180840-46f16b8d8fb0
github.com/tinkerbell/tink v0.6.1-0.20220426181411-59b0126c7dc0
github.com/tinkerbell/tink v0.6.1-0.20220506205527-97aa134e7938
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.21.0
go.opentelemetry.io/otel v1.3.0
go.opentelemetry.io/otel/trace v1.3.0
Expand Down Expand Up @@ -230,7 +230,7 @@ require (
k8s.io/api v0.23.0 // indirect
k8s.io/apiextensions-apiserver v0.23.0 // indirect
k8s.io/component-base v0.23.0 // indirect
k8s.io/klog/v2 v2.30.0 // indirect
k8s.io/klog/v2 v2.60.1 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b // indirect
mvdan.cc/gofumpt v0.3.0 // indirect
Expand Down
Loading