Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
Signed-off-by: galal-hussein <[email protected]>
  • Loading branch information
galal-hussein committed Jan 22, 2025
1 parent 97c34c2 commit 67827d5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
2 changes: 1 addition & 1 deletion k3k-kubelet/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ func (p *Provider) configureNetworking(podName, podNamespace string, pod *corev1
// inject serverIP to hostalias for the pod
KubernetesHostAlias := corev1.HostAlias{
IP: serverIP,
Hostnames: []string{"kubernetes", "kubernetes.default", "kubernetes.default.svc.cluster.local"},
Hostnames: []string{"kubernetes", "kubernetes.default", "kubernetes.default.svc", "kubernetes.default.svc.cluster", "kubernetes.default.svc.cluster.local"},
}
pod.Spec.HostAliases = append(pod.Spec.HostAliases, KubernetesHostAlias)
// inject networking information to the pod's environment variables
Expand Down
18 changes: 17 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main

import (
"context"
"errors"
"fmt"
"os"

Expand All @@ -15,6 +16,7 @@ import (
"github.com/rancher/k3k/pkg/log"
"github.com/urfave/cli"
"go.uber.org/zap"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/clientcmd"
Expand Down Expand Up @@ -54,7 +56,7 @@ var (
cli.StringFlag{
Name: "shared-agent-pull-policy",
EnvVar: "SHARED_AGENT_PULL_POLICY",
Usage: "K3K Virtual Kubelet image pull policy",
Usage: "K3K Virtual Kubelet image pull policy must be one of Always, IfNotPresent or Never",
Destination: &sharedAgentImagePullPolicy,
},
cli.BoolFlag{
Expand All @@ -77,6 +79,9 @@ func main() {
app.Action = run
app.Version = buildinfo.Version
app.Before = func(clx *cli.Context) error {
if err := validate(); err != nil {
return err
}
logger = log.New(debug)
return nil
}
Expand Down Expand Up @@ -132,3 +137,14 @@ func run(clx *cli.Context) error {

return nil
}

func validate() error {
if sharedAgentImagePullPolicy != "" {
if sharedAgentImagePullPolicy != string(v1.PullAlways) &&
sharedAgentImagePullPolicy != string(v1.PullIfNotPresent) &&
sharedAgentImagePullPolicy != string(v1.PullNever) {
return errors.New("invalid value for shared agent image policy")
}
}
return nil
}
26 changes: 13 additions & 13 deletions pkg/controller/cluster/agent/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,20 @@ const (
)

type SharedAgent struct {
cluster *v1alpha1.Cluster
serviceIP string
sharedAgentImage string
sharedAgentImagePullPolicy string
token string
cluster *v1alpha1.Cluster
serviceIP string
image string
imagePullPolicy string
token string
}

func NewSharedAgent(cluster *v1alpha1.Cluster, serviceIP, sharedAgentImage, sharedAgentImagePullPolicy, token string) Agent {
func NewSharedAgent(cluster *v1alpha1.Cluster, serviceIP, image, imagePullPolicy, token string) Agent {
return &SharedAgent{
cluster: cluster,
serviceIP: serviceIP,
sharedAgentImage: sharedAgentImage,
sharedAgentImagePullPolicy: sharedAgentImagePullPolicy,
token: token,
cluster: cluster,
serviceIP: serviceIP,
image: image,
imagePullPolicy: imagePullPolicy,
token: token,
}
}

Expand Down Expand Up @@ -179,8 +179,8 @@ func (s *SharedAgent) podSpec(affinitySelector *metav1.LabelSelector) v1.PodSpec
Containers: []v1.Container{
{
Name: s.Name(),
Image: s.sharedAgentImage,
ImagePullPolicy: v1.PullPolicy(s.sharedAgentImagePullPolicy),
Image: s.image,
ImagePullPolicy: v1.PullPolicy(s.imagePullPolicy),
Resources: v1.ResourceRequirements{
Limits: limit,
},
Expand Down

0 comments on commit 67827d5

Please sign in to comment.