Skip to content

Commit

Permalink
Fix naming throughout the package
Browse files Browse the repository at this point in the history
Signed-off-by: galal-hussein <[email protected]>
  • Loading branch information
galal-hussein committed Oct 17, 2024
1 parent d17ae34 commit 070389c
Show file tree
Hide file tree
Showing 27 changed files with 453 additions and 393 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
with:
context: .
push: true
tags: rancher/k3k:k3k-kubelet
tags: rancher/k3k:k3k-kubelet-dev
file: package/Dockerfile.kubelet
platforms: linux/amd64

Expand Down
4 changes: 3 additions & 1 deletion charts/k3k/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ spec:
- image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
name: {{ .Chart.Name }}
environment:
env:
- name: CLUSTER_CIDR
value: {{ .Values.host.clusterCIDR }}
- name: SHARED_AGENT_IMAGE
value: "{{ .Values.sharedAgent.image.repository }}:{{ .Values.sharedAgent.image.tag }}"
ports:
- containerPort: 8080
name: https
Expand Down
6 changes: 6 additions & 0 deletions charts/k3k/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ serviceAccount:
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name: ""

# configuration related to the shared agent mode in k3k
sharedAgent:
image:
repository: "rancher/k3k"
tag: "k3k-kubelet-dev"
22 changes: 6 additions & 16 deletions cli/cmds/cluster/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,26 @@ import (
"os"
"path/filepath"
"strings"
"time"

"github.com/rancher/k3k/cli/cmds"
"github.com/rancher/k3k/pkg/apis/k3k.io/v1alpha1"
"github.com/rancher/k3k/pkg/controller"
"github.com/rancher/k3k/pkg/controller/cluster"
"github.com/rancher/k3k/pkg/controller/cluster/server"
"github.com/rancher/k3k/pkg/controller/kubeconfig"
"github.com/rancher/k3k/pkg/controller/util"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apiserver/pkg/authentication/user"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/retry"
"sigs.k8s.io/controller-runtime/pkg/client"
)

var (
Scheme = runtime.NewScheme()
backoff = wait.Backoff{
Steps: 5,
Duration: 20 * time.Second,
Factor: 2,
Jitter: 0.1,
}
)
var Scheme = runtime.NewScheme()

func init() {
_ = clientgoscheme.AddToScheme(Scheme)
Expand Down Expand Up @@ -120,7 +110,7 @@ var (

func create(clx *cli.Context) error {
ctx := context.Background()
if err := validateCreateFlags(clx); err != nil {
if err := validateCreateFlags(); err != nil {
return err
}

Expand Down Expand Up @@ -173,13 +163,13 @@ func create(clx *cli.Context) error {

logrus.Infof("Extracting Kubeconfig for [%s] cluster", name)
cfg := &kubeconfig.KubeConfig{
CN: util.AdminCommonName,
CN: controller.AdminCommonName,
ORG: []string{user.SystemPrivilegedGroup},
ExpiryDate: 0,
}
logrus.Infof("waiting for cluster to be available..")
var kubeconfig []byte
if err := retry.OnError(backoff, apierrors.IsNotFound, func() error {
if err := retry.OnError(controller.Backoff, apierrors.IsNotFound, func() error {
kubeconfig, err = cfg.Extract(ctx, ctrlClient, cluster, host[0])
if err != nil {
return err
Expand All @@ -203,7 +193,7 @@ func create(clx *cli.Context) error {
return os.WriteFile(cluster.Name+"-kubeconfig.yaml", kubeconfig, 0644)
}

func validateCreateFlags(clx *cli.Context) error {
func validateCreateFlags() error {
if persistenceType != server.EphermalNodesType &&
persistenceType != server.DynamicNodesType {
return errors.New("invalid persistence type")
Expand Down
27 changes: 10 additions & 17 deletions cli/cmds/kubeconfig/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import (

"github.com/rancher/k3k/cli/cmds"
"github.com/rancher/k3k/pkg/apis/k3k.io/v1alpha1"
"github.com/rancher/k3k/pkg/controller"
"github.com/rancher/k3k/pkg/controller/kubeconfig"
"github.com/rancher/k3k/pkg/controller/util"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apiserver/pkg/authentication/user"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/clientcmd"
Expand All @@ -31,19 +30,13 @@ func init() {
}

var (
Scheme = runtime.NewScheme()
name string
cn string
org cli.StringSlice
altNames cli.StringSlice
expirationDays int64
configName string
backoff = wait.Backoff{
Steps: 5,
Duration: 20 * time.Second,
Factor: 2,
Jitter: 0.1,
}
Scheme = runtime.NewScheme()
name string
cn string
org cli.StringSlice
altNames cli.StringSlice
expirationDays int64
configName string
generateKubeconfigFlags = []cli.Flag{
cli.StringFlag{
Name: "name",
Expand All @@ -59,7 +52,7 @@ var (
Name: "cn",
Usage: "Common name (CN) of the generated certificates for the kubeconfig",
Destination: &cn,
Value: util.AdminCommonName,
Value: controller.AdminCommonName,
},
cli.StringSliceFlag{
Name: "org",
Expand Down Expand Up @@ -141,7 +134,7 @@ func generate(clx *cli.Context) error {
}
logrus.Infof("waiting for cluster to be available..")
var kubeconfig []byte
if err := retry.OnError(backoff, apierrors.IsNotFound, func() error {
if err := retry.OnError(controller.Backoff, apierrors.IsNotFound, func() error {
kubeconfig, err = cfg.Extract(ctx, ctrlClient, &cluster, host[0])
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
go.etcd.io/etcd/api/v3 v3.5.14
go.etcd.io/etcd/client/v3 v3.5.14
go.uber.org/zap v1.26.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.31.1
k8s.io/apimachinery v0.31.1
k8s.io/apiserver v0.31.0
Expand Down Expand Up @@ -120,7 +121,6 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.29.2 // indirect
k8s.io/component-base v0.29.2 // indirect
k8s.io/kms v0.29.2 // indirect
Expand Down
58 changes: 31 additions & 27 deletions k3k-kubelet/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,56 @@ import (

// Config has all virtual-kubelet startup options
type config struct {
clusterName string `yaml:"clusterName"`
clusterNamespace string `yaml:"clusterNamespace"`
hostConfigPath string `yaml:"hostConfigPath"`
virtualConfigPath string `yaml:"virtualConfigPath"`
kubeletPort string `yaml:"kubeletPort"`
nodeName string `yaml:"nodeName"`
agentPodIP string `yaml:"agentPodIP"`
token string `yaml:"token"`
ClusterName string `yaml:"clusterName,omitempty"`
ClusterNamespace string `yaml:"clusterNamespace,omitempty"`
NodeName string `yaml:"nodeName,omitempty"`
Token string `yaml:"token,omitempty"`
AgentHostname string `yaml:"agentHostname,omitempty"`
HostConfigPath string `yaml:"hostConfigPath,omitempty"`
VirtualConfigPath string `yaml:"virtualConfigPath,omitempty"`
KubeletPort string `yaml:"kubeletPort,omitempty"`
}

func (t *config) UnmarshalYAML(data []byte) error {
func (t *config) unmarshalYAML(data []byte) error {
var c config

if err := yaml.Unmarshal(data, &c); err != nil {
return err
}
if t.clusterName == "" {
t.clusterName = c.clusterName

if t.ClusterName == "" {
t.ClusterName = c.ClusterName
}
if t.ClusterNamespace == "" {
t.ClusterNamespace = c.ClusterNamespace
}
if t.clusterNamespace == "" {
t.clusterNamespace = c.clusterNamespace
if t.HostConfigPath == "" {
t.HostConfigPath = c.HostConfigPath
}
if t.hostConfigPath == "" {
t.hostConfigPath = c.hostConfigPath
if t.VirtualConfigPath == "" {
t.VirtualConfigPath = c.VirtualConfigPath
}
if t.virtualConfigPath == "" {
t.virtualConfigPath = c.virtualConfigPath
if t.KubeletPort == "" {
t.KubeletPort = c.KubeletPort
}
if t.kubeletPort == "" {
t.kubeletPort = c.kubeletPort
if t.AgentHostname == "" {
t.AgentHostname = c.AgentHostname
}
if t.nodeName == "" {
t.nodeName = c.nodeName
if t.NodeName == "" {
t.NodeName = c.NodeName
}

return nil
}

func (t *config) Validate() error {
if t.clusterName == "" {
if t.ClusterName == "" {
return errors.New("cluster name is not provided")
}
if t.clusterNamespace == "" {
if t.ClusterNamespace == "" {
return errors.New("cluster namespace is not provided")
}
if t.agentPodIP == "" {
return errors.New("agent POD IP is not provided")
if t.AgentHostname == "" {
return errors.New("agent Hostname is not provided")
}
return nil
}
Expand All @@ -68,5 +72,5 @@ func (t *config) Parse(path string) error {
if err != nil {
return err
}
return t.UnmarshalYAML(configFileBytes)
return t.unmarshalYAML(configFileBytes)
}
Loading

0 comments on commit 070389c

Please sign in to comment.