Skip to content

Commit

Permalink
Patches after 0.3.0 rc reviews (#254)
Browse files Browse the repository at this point in the history
- Enhance debug information for status report
- print version of the interlink binary
- vk node is now starting in notReady, not allowing pending pod to be polled unless the remote side is OK
- telemetry endpoint is now configurable
- CPU and memory allocatable resources are now taken correctly from the config file

Signed-off-by: Diego Ciangottini <[email protected]>

---------

Signed-off-by: Diego Ciangottini <[email protected]>
  • Loading branch information
dciangot authored Jul 10, 2024
1 parent a6f608b commit f0754cb
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 94 deletions.
2 changes: 2 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ builds:
main: ./cmd/virtual-kubelet
- id: "interlink"
binary: interlink
hooks:
pre: bash -c "KUBELET_VERSION={{.Version}} ./cmd/virtual-kubelet/set-version.sh"
env:
- CGO_ENABLED=0
goos:
Expand Down
11 changes: 4 additions & 7 deletions cmd/installer/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ spec:
labels:
nodeName: {{.VKName}}
spec:
#hostNetwork: true
dnsConfig:
nameservers:
- 8.8.8.8
containers:
- name: jaeger
image: jaegertracing/all-in-one:1.51
- name: inttw-vk
image: ghcr.io/intertwin-eu/interlink/virtual-kubelet-inttw:{{.InterLinkVersion}}
imagePullPolicy: Always
Expand Down Expand Up @@ -54,7 +54,6 @@ spec:
env:
- name: IAM_TOKEN_ENDPOINT
value: {{.OAUTH.TokenURL}}
# TODO load env IAM client from secret
- name: IAM_CLIENT_ID
value: {{.OAUTH.ClientID}}
- name: IAM_CLIENT_SECRET
Expand Down Expand Up @@ -87,6 +86,4 @@ spec:
# Provide the name of the ConfigMap you want to mount.
name: {{.VKName}}-config
- name: token
hostPath:
path: /tmp
type: Directory
emptyDir: {}
18 changes: 15 additions & 3 deletions cmd/interlink/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,32 @@ package main

import (
"context"
"flag"
"fmt"
"net/http"
"strings"

"github.com/sirupsen/logrus"
"github.com/virtual-kubelet/virtual-kubelet/log"
logruslogger "github.com/virtual-kubelet/virtual-kubelet/log/logrus"

commonIL "github.com/intertwin-eu/interlink/pkg/interlink"
types "github.com/intertwin-eu/interlink/pkg/interlink"
"github.com/intertwin-eu/interlink/pkg/interlink/api"
"github.com/intertwin-eu/interlink/pkg/virtualkubelet"
)

func main() {
printVersion := flag.Bool("version", false, "show version")
flag.Parse()

if *printVersion {
fmt.Println(virtualkubelet.KubeletVersion)
return
}
var cancel context.CancelFunc
api.PodStatuses.Statuses = make(map[string]commonIL.PodStatus)
api.PodStatuses.Statuses = make(map[string]types.PodStatus)

interLinkConfig, err := commonIL.NewInterLinkConfig()
interLinkConfig, err := types.NewInterLinkConfig()
if err != nil {
panic(err)
}
Expand All @@ -36,6 +46,8 @@ func main() {

log.G(ctx).Info(interLinkConfig)

log.G(ctx).Info("interLink version: ", virtualkubelet.KubeletVersion)

sidecarEndpoint := ""
if strings.HasPrefix(interLinkConfig.Sidecarurl, "unix://") {
sidecarEndpoint = interLinkConfig.Sidecarurl
Expand Down
9 changes: 8 additions & 1 deletion cmd/virtual-kubelet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,14 @@ func initProvider() (func(context.Context) error, error) {
// probably connect directly to the service through dns.
ctx, cancel := context.WithTimeout(ctx, time.Second)
defer cancel()
conn, err := grpc.DialContext(ctx, "localhost:4317",

otlpEndpoint := os.Getenv("TELEMETRY_ENDPOINT")

if otlpEndpoint == "" {
otlpEndpoint = "localhost:4317"
}

conn, err := grpc.DialContext(ctx, otlpEndpoint,
// Note the use of insecure transport here. TLS is recommended in production.
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
Expand Down
2 changes: 2 additions & 0 deletions docker/Dockerfile.interlink
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ ENV GOCACHE="/go/build-cache"

RUN mkdir -p $GOMODCACHE && mkdir -p $GOCACHE

ARG VERSION
RUN bash -c "KUBELET_VERSION=${VERSION} ./cmd/virtual-kubelet/set-version.sh"

RUN go mod tidy
RUN CGO_ENABLED=0 GOOS=linux go build -o bin/interlink cmd/interlink/main.go
Expand Down
10 changes: 5 additions & 5 deletions pkg/interlink/api/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/containerd/containerd/log"

commonIL "github.com/intertwin-eu/interlink/pkg/interlink"
types "github.com/intertwin-eu/interlink/pkg/interlink"
)

// CreateHandler collects and rearranges all needed ConfigMaps/Secrets/EmptyDirs to ship them to the sidecar, then sends a response to the client
Expand All @@ -25,8 +25,8 @@ func (h *InterLinkHandler) CreateHandler(w http.ResponseWriter, r *http.Request)
return
}

var req *http.Request //request to forward to sidecar
var pod commonIL.PodCreateRequests //request for interlink
var req *http.Request //request to forward to sidecar
var pod types.PodCreateRequests //request for interlink
err = json.Unmarshal(bodyBytes, &pod)
if err != nil {
statusCode = http.StatusInternalServerError
Expand All @@ -35,9 +35,9 @@ func (h *InterLinkHandler) CreateHandler(w http.ResponseWriter, r *http.Request)
return
}

var retrievedData []commonIL.RetrievedPodData
var retrievedData []types.RetrievedPodData

data := commonIL.RetrievedPodData{}
data := types.RetrievedPodData{}
if h.Config.ExportPodData {
data, err = getData(h.Ctx, h.Config, pod)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions pkg/interlink/api/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/containerd/containerd/log"
v1 "k8s.io/api/core/v1"

commonIL "github.com/intertwin-eu/interlink/pkg/interlink"
types "github.com/intertwin-eu/interlink/pkg/interlink"
)

// DeleteHandler deletes the cached status for the provided Pod and forwards the request to the sidecar
Expand Down Expand Up @@ -64,8 +64,8 @@ func (h *InterLinkHandler) DeleteHandler(w http.ResponseWriter, r *http.Request)
w.WriteHeader(http.StatusOK)
}
log.G(h.Ctx).Debug("InterLink: " + string(returnValue))
var returnJson []commonIL.PodStatus
returnJson = append(returnJson, commonIL.PodStatus{PodName: pod.Name, PodUID: string(pod.UID), PodNamespace: pod.Namespace})
var returnJson []types.PodStatus
returnJson = append(returnJson, types.PodStatus{PodName: pod.Name, PodUID: string(pod.UID), PodNamespace: pod.Namespace})

bodyBytes, err = json.Marshal(returnJson)
if err != nil {
Expand Down
24 changes: 12 additions & 12 deletions pkg/interlink/api/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,31 @@ import (
"github.com/containerd/containerd/log"
v1 "k8s.io/api/core/v1"

commonIL "github.com/intertwin-eu/interlink/pkg/interlink"
types "github.com/intertwin-eu/interlink/pkg/interlink"
)

type MutexStatuses struct {
mu sync.Mutex
Statuses map[string]commonIL.PodStatus
Statuses map[string]types.PodStatus
}

var PodStatuses MutexStatuses

// getData retrieves ConfigMaps, Secrets and EmptyDirs from the provided pod by calling the retrieveData function.
// The config is needed by the retrieveData function.
// The function aggregates the return values of retrieveData function in a commonIL.RetrievedPodData variable and returns it, along with the first encountered error.
func getData(ctx context.Context, config commonIL.InterLinkConfig, pod commonIL.PodCreateRequests) (commonIL.RetrievedPodData, error) {
func getData(ctx context.Context, config types.InterLinkConfig, pod types.PodCreateRequests) (types.RetrievedPodData, error) {
log.G(ctx).Debug(pod.ConfigMaps)
var retrievedData commonIL.RetrievedPodData
var retrievedData types.RetrievedPodData
retrievedData.Pod = pod.Pod

for _, container := range pod.Pod.Spec.InitContainers {
log.G(ctx).Info("- Retrieving Secrets and ConfigMaps for the Docker Sidecar. InitContainer: " + container.Name)
log.G(ctx).Debug(container.VolumeMounts)
data, err := retrieveData(ctx, config, pod, container)
if err != nil {
log.G(ctx).Error(err)
return commonIL.RetrievedPodData{}, err
data, InterlinkIP := retrieveData(ctx, config, pod, container)
if InterlinkIP != nil {
log.G(ctx).Error(InterlinkIP)
return types.RetrievedPodData{}, InterlinkIP
}
retrievedData.Containers = append(retrievedData.Containers, data)
}
Expand All @@ -43,7 +43,7 @@ func getData(ctx context.Context, config commonIL.InterLinkConfig, pod commonIL.
data, err := retrieveData(ctx, config, pod, container)
if err != nil {
log.G(ctx).Error(err)
return commonIL.RetrievedPodData{}, err
return types.RetrievedPodData{}, err
}
retrievedData.Containers = append(retrievedData.Containers, data)
}
Expand All @@ -54,8 +54,8 @@ func getData(ctx context.Context, config commonIL.InterLinkConfig, pod commonIL.
// retrieveData retrieves ConfigMaps, Secrets and EmptyDirs.
// The config is needed to specify the EmptyDirs mounting point.
// It returns the retrieved data in a variable of type commonIL.RetrievedContainer and the first encountered error.
func retrieveData(ctx context.Context, config commonIL.InterLinkConfig, pod commonIL.PodCreateRequests, container v1.Container) (commonIL.RetrievedContainer, error) {
retrievedData := commonIL.RetrievedContainer{}
func retrieveData(ctx context.Context, config types.InterLinkConfig, pod types.PodCreateRequests, container v1.Container) (types.RetrievedContainer, error) {
retrievedData := types.RetrievedContainer{}
for _, mountVar := range container.VolumeMounts {
log.G(ctx).Debug("-- Retrieving data for mountpoint " + mountVar.Name)

Expand Down Expand Up @@ -114,7 +114,7 @@ func checkIfCached(uid string) bool {
}

// updateStatuses locks and updates the PodStatuses map with the statuses contained in the returnedStatuses slice
func updateStatuses(returnedStatuses []commonIL.PodStatus) {
func updateStatuses(returnedStatuses []types.PodStatus) {
PodStatuses.mu.Lock()

for _, new := range returnedStatuses {
Expand Down
4 changes: 2 additions & 2 deletions pkg/interlink/api/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/containerd/containerd/log"

commonIL "github.com/intertwin-eu/interlink/pkg/interlink"
types "github.com/intertwin-eu/interlink/pkg/interlink"
)

func (h *InterLinkHandler) GetLogsHandler(w http.ResponseWriter, r *http.Request) {
Expand All @@ -22,7 +22,7 @@ func (h *InterLinkHandler) GetLogsHandler(w http.ResponseWriter, r *http.Request
}

log.G(h.Ctx).Info("InterLink: unmarshal GetLogs request")
var req2 commonIL.LogStruct //incoming request. To be used in interlink API. req is directly forwarded to sidecar
var req2 types.LogStruct //incoming request. To be used in interlink API. req is directly forwarded to sidecar
err = json.Unmarshal(bodyBytes, &req2)
if err != nil {
statusCode = http.StatusInternalServerError
Expand Down
6 changes: 3 additions & 3 deletions pkg/interlink/api/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/containerd/containerd/log"
v1 "k8s.io/api/core/v1"

commonIL "github.com/intertwin-eu/interlink/pkg/interlink"
types "github.com/intertwin-eu/interlink/pkg/interlink"
)

func (h *InterLinkHandler) StatusHandler(w http.ResponseWriter, r *http.Request) {
Expand All @@ -29,8 +29,8 @@ func (h *InterLinkHandler) StatusHandler(w http.ResponseWriter, r *http.Request)
}

var podsToBeChecked []*v1.Pod
var returnedStatuses []commonIL.PodStatus //returned from the query to the sidecar
var returnPods []commonIL.PodStatus //returned to the vk
var returnedStatuses []types.PodStatus //returned from the query to the sidecar
var returnPods []types.PodStatus //returned to the vk

PodStatuses.mu.Lock()
for _, pod := range pods {
Expand Down
8 changes: 4 additions & 4 deletions pkg/virtualkubelet/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package virtualkubelet

// VirtualKubeletConfig holds the whole configuration
type VirtualKubeletConfig struct {
Interlinkurl string `yaml:"InterlinkURL"`
InterlinkURL string `yaml:"InterlinkURL"`
Interlinkport string `yaml:"InterlinkPort"`
VKConfigPath string `yaml:"VKConfigPath"`
VKTokenFile string `yaml:"VKTokenFile"`
Expand All @@ -11,8 +11,8 @@ type VirtualKubeletConfig struct {
PodIP string `yaml:"PodIP"`
VerboseLogging bool `yaml:"VerboseLogging"`
ErrorsOnlyLogging bool `yaml:"ErrorsOnlyLogging"`
CPU string `yaml:"cpu,omitempty"`
Memory string `yaml:"memory,omitempty"`
Pods string `yaml:"pods,omitempty"`
CPU string `yaml:"CPU,omitempty"`
Memory string `yaml:"Memory,omitempty"`
Pods string `yaml:"Pods,omitempty"`
GPU string `yaml:"nvidia.com/gpu,omitempty"`
}
Loading

0 comments on commit f0754cb

Please sign in to comment.