mirror of
https://github.com/rancher/k3k.git
synced 2026-08-18 20:07:06 +00:00
Fix typos and adding spellcheck linter (#215)
* adding spellcheck linter * fix typos
This commit is contained in:
@@ -7,3 +7,6 @@ linters:
|
||||
- ineffassign
|
||||
- staticcheck
|
||||
- unused
|
||||
|
||||
# extra
|
||||
- misspell
|
||||
|
||||
@@ -84,8 +84,8 @@ var (
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "persistence-type",
|
||||
Usage: "Persistence mode for the nodes (ephermal, static, dynamic)",
|
||||
Value: server.EphermalNodesType,
|
||||
Usage: "Persistence mode for the nodes (ephemeral, static, dynamic)",
|
||||
Value: server.EphemeralNodesType,
|
||||
Destination: &persistenceType,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
@@ -229,7 +229,7 @@ func create(clx *cli.Context) error {
|
||||
}
|
||||
|
||||
func validateCreateFlags() error {
|
||||
if persistenceType != server.EphermalNodesType &&
|
||||
if persistenceType != server.EphemeralNodesType &&
|
||||
persistenceType != server.DynamicNodesType {
|
||||
return errors.New("invalid persistence type")
|
||||
}
|
||||
|
||||
@@ -26,9 +26,9 @@ type ControllerHandler struct {
|
||||
HostClient client.Client
|
||||
// VirtualClient is the client used to communicate with the virtual cluster
|
||||
VirtualClient client.Client
|
||||
// Translater is the translater that will be used to adjust objects before they
|
||||
// Translator is the translator that will be used to adjust objects before they
|
||||
// are made on the host cluster
|
||||
Translater translate.ToHostTranslater
|
||||
Translator translate.ToHostTranslator
|
||||
// Logger is the logger that the controller will use to log errors
|
||||
Logger *k3klog.Logger
|
||||
// controllers are the controllers which are currently running
|
||||
@@ -65,7 +65,7 @@ func (c *ControllerHandler) AddResource(ctx context.Context, obj client.Object)
|
||||
TranslateFunc: func(s *v1.Secret) (*v1.Secret, error) {
|
||||
// note that this doesn't do any type safety - fix this
|
||||
// when generics work
|
||||
c.Translater.TranslateTo(s)
|
||||
c.Translator.TranslateTo(s)
|
||||
// Remove service-account-token types when synced to the host
|
||||
if s.Type == v1.SecretTypeServiceAccountToken {
|
||||
s.Type = v1.SecretTypeOpaque
|
||||
@@ -80,7 +80,7 @@ func (c *ControllerHandler) AddResource(ctx context.Context, obj client.Object)
|
||||
VirtualClient: c.VirtualClient,
|
||||
// TODO: Need actual function
|
||||
TranslateFunc: func(s *v1.ConfigMap) (*v1.ConfigMap, error) {
|
||||
c.Translater.TranslateTo(s)
|
||||
c.Translator.TranslateTo(s)
|
||||
return s, nil
|
||||
},
|
||||
Logger: c.Logger,
|
||||
|
||||
@@ -31,12 +31,12 @@ type PVCReconciler struct {
|
||||
Scheme *runtime.Scheme
|
||||
HostScheme *runtime.Scheme
|
||||
logger *log.Logger
|
||||
Translater translate.ToHostTranslater
|
||||
Translator translate.ToHostTranslator
|
||||
}
|
||||
|
||||
// AddPVCSyncer adds persistentvolumeclaims syncer controller to k3k-kubelet
|
||||
func AddPVCSyncer(ctx context.Context, virtMgr, hostMgr manager.Manager, clusterName, clusterNamespace string, logger *log.Logger) error {
|
||||
translater := translate.ToHostTranslater{
|
||||
translator := translate.ToHostTranslator{
|
||||
ClusterName: clusterName,
|
||||
ClusterNamespace: clusterNamespace,
|
||||
}
|
||||
@@ -47,7 +47,7 @@ func AddPVCSyncer(ctx context.Context, virtMgr, hostMgr manager.Manager, cluster
|
||||
Scheme: virtMgr.GetScheme(),
|
||||
HostScheme: hostMgr.GetScheme(),
|
||||
logger: logger.Named(pvcController),
|
||||
Translater: translater,
|
||||
Translator: translator,
|
||||
clusterName: clusterName,
|
||||
clusterNamespace: clusterNamespace,
|
||||
}
|
||||
@@ -116,6 +116,6 @@ func (r *PVCReconciler) Reconcile(ctx context.Context, req reconcile.Request) (r
|
||||
|
||||
func (r *PVCReconciler) pvc(obj *v1.PersistentVolumeClaim) *v1.PersistentVolumeClaim {
|
||||
hostPVC := obj.DeepCopy()
|
||||
r.Translater.TranslateTo(hostPVC)
|
||||
r.Translator.TranslateTo(hostPVC)
|
||||
return hostPVC
|
||||
}
|
||||
|
||||
@@ -33,12 +33,12 @@ type ServiceReconciler struct {
|
||||
Scheme *runtime.Scheme
|
||||
HostScheme *runtime.Scheme
|
||||
logger *log.Logger
|
||||
Translater translate.ToHostTranslater
|
||||
Translator translate.ToHostTranslator
|
||||
}
|
||||
|
||||
// AddServiceSyncer adds service syncer controller to the manager of the virtual cluster
|
||||
func AddServiceSyncer(ctx context.Context, virtMgr, hostMgr manager.Manager, clusterName, clusterNamespace string, logger *log.Logger) error {
|
||||
translater := translate.ToHostTranslater{
|
||||
translator := translate.ToHostTranslator{
|
||||
ClusterName: clusterName,
|
||||
ClusterNamespace: clusterNamespace,
|
||||
}
|
||||
@@ -49,7 +49,7 @@ func AddServiceSyncer(ctx context.Context, virtMgr, hostMgr manager.Manager, clu
|
||||
Scheme: virtMgr.GetScheme(),
|
||||
HostScheme: hostMgr.GetScheme(),
|
||||
logger: logger.Named(serviceSyncerController),
|
||||
Translater: translater,
|
||||
Translator: translator,
|
||||
clusterName: clusterName,
|
||||
clusterNamespace: clusterNamespace,
|
||||
}
|
||||
@@ -120,7 +120,7 @@ func (s *ServiceReconciler) Reconcile(ctx context.Context, req reconcile.Request
|
||||
|
||||
func (s *ServiceReconciler) service(obj *v1.Service) *v1.Service {
|
||||
hostService := obj.DeepCopy()
|
||||
s.Translater.TranslateTo(hostService)
|
||||
s.Translator.TranslateTo(hostService)
|
||||
// don't sync finalizers to the host
|
||||
return hostService
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ var _ nodeutil.Provider = (*Provider)(nil)
|
||||
// TODO: Implement NotifyPods and the required usage so that this can be an async provider
|
||||
type Provider struct {
|
||||
Handler controller.ControllerHandler
|
||||
Translater translate.ToHostTranslater
|
||||
Translator translate.ToHostTranslator
|
||||
HostClient client.Client
|
||||
VirtualClient client.Client
|
||||
ClientConfig rest.Config
|
||||
@@ -72,7 +72,7 @@ func New(hostConfig rest.Config, hostMgr, virtualMgr manager.Manager, logger *k3
|
||||
return nil, err
|
||||
}
|
||||
|
||||
translater := translate.ToHostTranslater{
|
||||
translator := translate.ToHostTranslator{
|
||||
ClusterName: name,
|
||||
ClusterNamespace: namespace,
|
||||
}
|
||||
@@ -83,12 +83,12 @@ func New(hostConfig rest.Config, hostMgr, virtualMgr manager.Manager, logger *k3
|
||||
Scheme: *virtualMgr.GetScheme(),
|
||||
HostClient: hostMgr.GetClient(),
|
||||
VirtualClient: virtualMgr.GetClient(),
|
||||
Translater: translater,
|
||||
Translator: translator,
|
||||
Logger: logger,
|
||||
},
|
||||
HostClient: hostMgr.GetClient(),
|
||||
VirtualClient: virtualMgr.GetClient(),
|
||||
Translater: translater,
|
||||
Translator: translator,
|
||||
ClientConfig: hostConfig,
|
||||
CoreClient: coreClient,
|
||||
ClusterNamespace: namespace,
|
||||
@@ -103,7 +103,7 @@ func New(hostConfig rest.Config, hostMgr, virtualMgr manager.Manager, logger *k3
|
||||
|
||||
// GetContainerLogs retrieves the logs of a container by name from the provider.
|
||||
func (p *Provider) GetContainerLogs(ctx context.Context, namespace, podName, containerName string, opts api.ContainerLogOpts) (io.ReadCloser, error) {
|
||||
hostPodName := p.Translater.TranslateName(namespace, podName)
|
||||
hostPodName := p.Translator.TranslateName(namespace, podName)
|
||||
options := corev1.PodLogOptions{
|
||||
Container: containerName,
|
||||
Timestamps: opts.Timestamps,
|
||||
@@ -134,7 +134,7 @@ func (p *Provider) GetContainerLogs(ctx context.Context, namespace, podName, con
|
||||
// RunInContainer executes a command in a container in the pod, copying data
|
||||
// between in/out/err and the container's stdin/stdout/stderr.
|
||||
func (p *Provider) RunInContainer(ctx context.Context, namespace, podName, containerName string, cmd []string, attach api.AttachIO) error {
|
||||
hostPodName := p.Translater.TranslateName(namespace, podName)
|
||||
hostPodName := p.Translator.TranslateName(namespace, podName)
|
||||
req := p.CoreClient.RESTClient().Post().
|
||||
Resource("pods").
|
||||
Name(hostPodName).
|
||||
@@ -166,7 +166,7 @@ func (p *Provider) RunInContainer(ctx context.Context, namespace, podName, conta
|
||||
// AttachToContainer attaches to the executing process of a container in the pod, copying data
|
||||
// between in/out/err and the container's stdin/stdout/stderr.
|
||||
func (p *Provider) AttachToContainer(ctx context.Context, namespace, podName, containerName string, attach api.AttachIO) error {
|
||||
hostPodName := p.Translater.TranslateName(namespace, podName)
|
||||
hostPodName := p.Translator.TranslateName(namespace, podName)
|
||||
req := p.CoreClient.RESTClient().Post().
|
||||
Resource("pods").
|
||||
Name(hostPodName).
|
||||
@@ -241,7 +241,7 @@ func (p *Provider) GetStatsSummary(ctx context.Context) (*statsv1alpha1.Summary,
|
||||
|
||||
podsNameMap := make(map[string]*v1.Pod)
|
||||
for _, pod := range pods {
|
||||
hostPodName := p.Translater.TranslateName(pod.Namespace, pod.Name)
|
||||
hostPodName := p.Translator.TranslateName(pod.Namespace, pod.Name)
|
||||
podsNameMap[hostPodName] = pod
|
||||
}
|
||||
|
||||
@@ -289,7 +289,7 @@ func (p *Provider) GetMetricsResource(ctx context.Context) ([]*dto.MetricFamily,
|
||||
|
||||
// PortForward forwards a local port to a port on the pod
|
||||
func (p *Provider) PortForward(ctx context.Context, namespace, pod string, port int32, stream io.ReadWriteCloser) error {
|
||||
hostPodName := p.Translater.TranslateName(namespace, pod)
|
||||
hostPodName := p.Translator.TranslateName(namespace, pod)
|
||||
req := p.CoreClient.RESTClient().Post().
|
||||
Resource("pods").
|
||||
Name(hostPodName).
|
||||
@@ -326,7 +326,7 @@ func (p *Provider) CreatePod(ctx context.Context, pod *corev1.Pod) error {
|
||||
// createPod takes a Kubernetes Pod and deploys it within the provider.
|
||||
func (p *Provider) createPod(ctx context.Context, pod *corev1.Pod) error {
|
||||
tPod := pod.DeepCopy()
|
||||
p.Translater.TranslateTo(tPod)
|
||||
p.Translator.TranslateTo(tPod)
|
||||
|
||||
// get Cluster definition
|
||||
clusterKey := types.NamespacedName{
|
||||
@@ -414,7 +414,7 @@ func (p *Provider) transformVolumes(ctx context.Context, podNamespace string, vo
|
||||
if err := p.syncConfigmap(ctx, podNamespace, volume.ConfigMap.Name, optional); err != nil {
|
||||
return fmt.Errorf("unable to sync configmap volume %s: %w", volume.Name, err)
|
||||
}
|
||||
volume.ConfigMap.Name = p.Translater.TranslateName(podNamespace, volume.ConfigMap.Name)
|
||||
volume.ConfigMap.Name = p.Translator.TranslateName(podNamespace, volume.ConfigMap.Name)
|
||||
} else if volume.Secret != nil {
|
||||
if volume.Secret.Optional != nil {
|
||||
optional = *volume.Secret.Optional
|
||||
@@ -422,7 +422,7 @@ func (p *Provider) transformVolumes(ctx context.Context, podNamespace string, vo
|
||||
if err := p.syncSecret(ctx, podNamespace, volume.Secret.SecretName, optional); err != nil {
|
||||
return fmt.Errorf("unable to sync secret volume %s: %w", volume.Name, err)
|
||||
}
|
||||
volume.Secret.SecretName = p.Translater.TranslateName(podNamespace, volume.Secret.SecretName)
|
||||
volume.Secret.SecretName = p.Translator.TranslateName(podNamespace, volume.Secret.SecretName)
|
||||
} else if volume.Projected != nil {
|
||||
for _, source := range volume.Projected.Sources {
|
||||
if source.ConfigMap != nil {
|
||||
@@ -433,7 +433,7 @@ func (p *Provider) transformVolumes(ctx context.Context, podNamespace string, vo
|
||||
if err := p.syncConfigmap(ctx, podNamespace, configMapName, optional); err != nil {
|
||||
return fmt.Errorf("unable to sync projected configmap %s: %w", configMapName, err)
|
||||
}
|
||||
source.ConfigMap.Name = p.Translater.TranslateName(podNamespace, configMapName)
|
||||
source.ConfigMap.Name = p.Translator.TranslateName(podNamespace, configMapName)
|
||||
} else if source.Secret != nil {
|
||||
if source.Secret.Optional != nil {
|
||||
optional = *source.Secret.Optional
|
||||
@@ -445,7 +445,7 @@ func (p *Provider) transformVolumes(ctx context.Context, podNamespace string, vo
|
||||
}
|
||||
}
|
||||
} else if volume.PersistentVolumeClaim != nil {
|
||||
volume.PersistentVolumeClaim.ClaimName = p.Translater.TranslateName(podNamespace, volume.PersistentVolumeClaim.ClaimName)
|
||||
volume.PersistentVolumeClaim.ClaimName = p.Translator.TranslateName(podNamespace, volume.PersistentVolumeClaim.ClaimName)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -531,7 +531,7 @@ func (p *Provider) updatePod(ctx context.Context, pod *v1.Pod) error {
|
||||
|
||||
hostNamespaceName := types.NamespacedName{
|
||||
Namespace: p.ClusterNamespace,
|
||||
Name: p.Translater.TranslateName(pod.Namespace, pod.Name),
|
||||
Name: p.Translator.TranslateName(pod.Namespace, pod.Name),
|
||||
}
|
||||
|
||||
var currentHostPod corev1.Pod
|
||||
@@ -580,13 +580,13 @@ func (p *Provider) DeletePod(ctx context.Context, pod *corev1.Pod) error {
|
||||
// state, as well as the pod. DeletePod may be called multiple times for the same pod.
|
||||
func (p *Provider) deletePod(ctx context.Context, pod *corev1.Pod) error {
|
||||
p.logger.Infof("Got request to delete pod %s", pod.Name)
|
||||
hostName := p.Translater.TranslateName(pod.Namespace, pod.Name)
|
||||
hostName := p.Translator.TranslateName(pod.Namespace, pod.Name)
|
||||
err := p.CoreClient.Pods(p.ClusterNamespace).Delete(ctx, hostName, metav1.DeleteOptions{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to delete pod %s/%s: %w", pod.Namespace, pod.Name, err)
|
||||
}
|
||||
if err = p.pruneUnusedVolumes(ctx, pod); err != nil {
|
||||
// note that we don't return an error here. The pod was sucessfully deleted, another process
|
||||
// note that we don't return an error here. The pod was successfully deleted, another process
|
||||
// should clean this without affecting the user
|
||||
p.logger.Errorf("failed to prune leftover volumes for %s/%s: %w, resources may be left", pod.Namespace, pod.Name, err)
|
||||
}
|
||||
@@ -656,14 +656,14 @@ func (p *Provider) GetPod(ctx context.Context, namespace, name string) (*corev1.
|
||||
p.logger.Debugw("got a request for get pod", "Namespace", namespace, "Name", name)
|
||||
hostNamespaceName := types.NamespacedName{
|
||||
Namespace: p.ClusterNamespace,
|
||||
Name: p.Translater.TranslateName(namespace, name),
|
||||
Name: p.Translator.TranslateName(namespace, name),
|
||||
}
|
||||
var pod corev1.Pod
|
||||
err := p.HostClient.Get(ctx, hostNamespaceName, &pod)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error when retrieving pod: %w", err)
|
||||
}
|
||||
p.Translater.TranslateFrom(&pod)
|
||||
p.Translator.TranslateFrom(&pod)
|
||||
return &pod, nil
|
||||
}
|
||||
|
||||
@@ -699,7 +699,7 @@ func (p *Provider) GetPods(ctx context.Context) ([]*corev1.Pod, error) {
|
||||
}
|
||||
retPods := []*corev1.Pod{}
|
||||
for _, pod := range podList.DeepCopy().Items {
|
||||
p.Translater.TranslateFrom(&pod)
|
||||
p.Translator.TranslateFrom(&pod)
|
||||
retPods = append(retPods, &pod)
|
||||
}
|
||||
return retPods, nil
|
||||
@@ -740,7 +740,7 @@ func (p *Provider) configureNetworking(podName, podNamespace string, pod *corev1
|
||||
},
|
||||
)
|
||||
}
|
||||
// handle init contianers as well
|
||||
// handle init containers as well
|
||||
for i := range pod.Spec.InitContainers {
|
||||
pod.Spec.InitContainers[i].Env = append(pod.Spec.InitContainers[i].Env,
|
||||
corev1.EnvVar{
|
||||
|
||||
@@ -52,7 +52,7 @@ func (p *Provider) transformTokens(ctx context.Context, pod, tPod *corev1.Pod) e
|
||||
hostSecret := virtualSecret.DeepCopy()
|
||||
hostSecret.Type = ""
|
||||
hostSecret.Annotations = make(map[string]string)
|
||||
p.Translater.TranslateTo(hostSecret)
|
||||
p.Translator.TranslateTo(hostSecret)
|
||||
|
||||
if err := p.HostClient.Create(ctx, hostSecret); err != nil {
|
||||
if !apierrors.IsAlreadyExists(err) {
|
||||
|
||||
@@ -20,12 +20,12 @@ const (
|
||||
ResourceNamespaceAnnotation = "k3k.io/namespace"
|
||||
)
|
||||
|
||||
type ToHostTranslater struct {
|
||||
type ToHostTranslator struct {
|
||||
// ClusterName is the name of the virtual cluster whose resources we are
|
||||
// translating to a host cluster
|
||||
ClusterName string
|
||||
// ClusterNamespace is the namespace of the virtual cluster whose resources
|
||||
// we are tranlsating to a host cluster
|
||||
// we are translating to a host cluster
|
||||
ClusterNamespace string
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ type ToHostTranslater struct {
|
||||
// static resources such as configmaps/secrets, and not for things like pods (which can reference other
|
||||
// objects). Note that this won't set host-cluster values (like resource version) so when updating you
|
||||
// may need to fetch the existing value and do some combination before using this.
|
||||
func (t *ToHostTranslater) TranslateTo(obj client.Object) {
|
||||
func (t *ToHostTranslator) TranslateTo(obj client.Object) {
|
||||
// owning objects may be in the virtual cluster, but may not be in the host cluster
|
||||
obj.SetOwnerReferences(nil)
|
||||
// add some annotations to make it easier to track source object
|
||||
@@ -63,7 +63,7 @@ func (t *ToHostTranslater) TranslateTo(obj client.Object) {
|
||||
obj.SetFinalizers(nil)
|
||||
}
|
||||
|
||||
func (t *ToHostTranslater) TranslateFrom(obj client.Object) {
|
||||
func (t *ToHostTranslator) TranslateFrom(obj client.Object) {
|
||||
// owning objects may be in the virtual cluster, but may not be in the host cluster
|
||||
obj.SetOwnerReferences(nil)
|
||||
|
||||
@@ -91,7 +91,7 @@ func (t *ToHostTranslater) TranslateFrom(obj client.Object) {
|
||||
}
|
||||
|
||||
// TranslateName returns the name of the resource in the host cluster. Will not update the object with this name.
|
||||
func (t *ToHostTranslater) TranslateName(namespace string, name string) string {
|
||||
func (t *ToHostTranslator) TranslateName(namespace string, name string) string {
|
||||
// we need to come up with a name which is:
|
||||
// - somewhat connectable to the original resource
|
||||
// - a valid k8s name
|
||||
|
||||
@@ -134,7 +134,7 @@ type ClusterList struct {
|
||||
}
|
||||
|
||||
type PersistenceConfig struct {
|
||||
// Type can be ephermal, static, dynamic
|
||||
// Type can be ephemeral, static, dynamic
|
||||
// +kubebuilder:default="ephemeral"
|
||||
Type string `json:"type"`
|
||||
StorageClassName string `json:"storageClassName,omitempty"`
|
||||
|
||||
@@ -188,7 +188,7 @@ func (c *ClusterReconciler) createCluster(ctx context.Context, cluster *v1alpha1
|
||||
return err
|
||||
}
|
||||
|
||||
// creating statefulsets in case the user chose a persistence type other than ephermal
|
||||
// creating statefulsets in case the user chose a persistence type other than ephemeral
|
||||
if err := c.server(ctx, cluster, s); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@ const (
|
||||
configName = "server-config"
|
||||
initConfigName = "init-server-config"
|
||||
|
||||
ServerPort = 6443
|
||||
EphermalNodesType = "ephermal"
|
||||
DynamicNodesType = "dynamic"
|
||||
ServerPort = 6443
|
||||
EphemeralNodesType = "ephemeral"
|
||||
DynamicNodesType = "dynamic"
|
||||
)
|
||||
|
||||
// Server
|
||||
@@ -229,7 +229,7 @@ func (s *Server) StatefulServer(ctx context.Context) (*apps.StatefulSet, error)
|
||||
|
||||
replicas = *s.cluster.Spec.Servers
|
||||
|
||||
if s.cluster.Spec.Persistence != nil && s.cluster.Spec.Persistence.Type != EphermalNodesType {
|
||||
if s.cluster.Spec.Persistence != nil && s.cluster.Spec.Persistence.Type != EphemeralNodesType {
|
||||
persistent = true
|
||||
pvClaims = []v1.PersistentVolumeClaim{
|
||||
{
|
||||
|
||||
@@ -239,7 +239,7 @@ var _ = Describe("ClusterSet Controller", func() {
|
||||
|
||||
})
|
||||
|
||||
When("created specifing the mode", func() {
|
||||
When("created specifying the mode", func() {
|
||||
It("should have the 'virtual' mode if specified", func() {
|
||||
clusterSet := &v1alpha1.ClusterSet{
|
||||
ObjectMeta: v1.ObjectMeta{
|
||||
@@ -306,7 +306,7 @@ var _ = Describe("ClusterSet Controller", func() {
|
||||
})
|
||||
})
|
||||
|
||||
When("created specifing the podSecurityAdmissionLevel", func() {
|
||||
When("created specifying the podSecurityAdmissionLevel", func() {
|
||||
It("should add and update the proper pod-security labels to the namespace", func() {
|
||||
var (
|
||||
privileged = v1alpha1.PrivilegedPodSecurityAdmissionLevel
|
||||
|
||||
Reference in New Issue
Block a user