Skip to content

Commit

Permalink
Merge pull request #30 from FabianKramm/main
Browse files Browse the repository at this point in the history
KubeletPort, PVC delete & flag fix
  • Loading branch information
FabianKramm authored May 26, 2021
2 parents ad58567 + 66fd964 commit 856f6d3
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
/api
/kubeconfig.yaml
/cmd/virtualclusterctl
/test
/conformance
/docs
devspace.yaml
2 changes: 1 addition & 1 deletion cmd/vcluster/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func Execute(cobraCmd *cobra.Command, args []string, options *context.VirtualClu
}

// set kubelet port
nodeservice.KubeletPort = int32(options.Port)
nodeservice.KubeletTargetPort = options.Port

// retrieve current namespace
if options.TargetNamespace == "" {
Expand Down
1 change: 0 additions & 1 deletion cmd/vclusterctl/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ vcluster create test --namespace test
cobraCmd.Flags().StringVar(&cmd.ChartName, "chart-name", "vcluster", "The virtual cluster chart name to use")
cobraCmd.Flags().StringVar(&cmd.ChartRepo, "chart-repo", "https://charts.loft.sh", "The virtual cluster chart repo to use")
cobraCmd.Flags().StringVar(&cmd.ReleaseValues, "release-values", "", "Path where to load the virtual cluster helm release values from")
cobraCmd.Flags().StringVar(&cmd.ReleaseValues, "release-values", "", "Path where to load the virtual cluster helm release values from")
cobraCmd.Flags().StringVar(&cmd.K3SImage, "k3s-image", "", "If specified, use this k3s image version")
cobraCmd.Flags().StringSliceVarP(&cmd.ExtraValues, "extra-values", "f", []string{}, "Path where to load extra helm values from")
cobraCmd.Flags().BoolVar(&cmd.CreateNamespace, "create-namespace", true, "If true the namespace will be created if it does not exist")
Expand Down
31 changes: 29 additions & 2 deletions cmd/vclusterctl/cmd/delete.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package cmd

import (
"context"
"fmt"
"github.com/pkg/errors"
kerrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"os/exec"

"github.com/loft-sh/vcluster/cmd/vclusterctl/flags"
Expand All @@ -16,7 +21,9 @@ type DeleteCmd struct {
*flags.GlobalFlags

Namespace string
log log.Logger
KeepPVC bool

log log.Logger
}

// NewDeleteCmd creates a new command
Expand Down Expand Up @@ -46,6 +53,7 @@ vcluster delete test --namespace test
}

cobraCmd.Flags().StringVarP(&cmd.Namespace, "namespace", "n", "", "The namespace the vcluster was created in")
cobraCmd.Flags().BoolVar(&cmd.KeepPVC, "keep-pvc", false, "If enabled, vcluster will not delete the persistent volume claim of the vcluster")
return cobraCmd
}

Expand Down Expand Up @@ -81,12 +89,31 @@ func (cmd *DeleteCmd) Run(cobraCmd *cobra.Command, args []string) error {
namespace = cmd.Namespace
}

// we have to upgrade / install the chart
// we have to delete the chart
err = helm.NewClient(&rawConfig, cmd.log).Delete(args[0], namespace)
if err != nil {
return err
}

// try to delete the pvc
if cmd.KeepPVC == false {
pvcName := fmt.Sprintf("data-%s-0", args[0])
restConfig, err := kubeClientConfig.ClientConfig()
if err != nil {
return err
}

client, err := kubernetes.NewForConfig(restConfig)
if err != nil {
return err
}

err = client.CoreV1().PersistentVolumeClaims(namespace).Delete(context.Background(), pvcName, metav1.DeleteOptions{})
if err != nil && kerrors.IsNotFound(err) == false {
return errors.Wrap(err, "delete pvc")
}
}

cmd.log.Donef("Successfully deleted virtual cluster %s in namespace %s", args[0], namespace)
return nil
}
7 changes: 2 additions & 5 deletions devspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,10 @@ profiles:
vcluster:
image: rancher/k3s:v1.20.5-k3s1
extraArgs:
- --service-cidr=10.108.0.0/20
- --service-cidr=10.68.0.0/20
rbac:
clusterRole:
create: true
syncer:
image: ghcr.io/loft-sh/loft-enterprise/dev-vcluster
extraArgs:
- --sync-all-nodes
- --sync-node-changes
- --fake-nodes=false
extraArgs: []
6 changes: 3 additions & 3 deletions docs/pages/operator/external-access.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ vcluster create my-vcluster -n my-vcluster -f values.yaml

Retrieve the kube config via:
```
vcluster connect my-vcluster -n my-vcluster --server=x.x.x.x
vcluster connect my-vcluster -n my-vcluster --server=https://x.x.x.x
```

Access the vcluster:
Expand Down Expand Up @@ -122,7 +122,7 @@ vcluster create my-vcluster -n my-vcluster -f values.yaml

Retrieve the kube config via:
```
vcluster connect my-vcluster -n my-vcluster --server=x.x.x.x
vcluster connect my-vcluster -n my-vcluster --server=https://x.x.x.x
```

Access the vcluster:
Expand Down Expand Up @@ -180,7 +180,7 @@ vcluster create my-vcluster -n my-vcluster -f values.yaml

Retrieve the kube config via:
```
vcluster connect my-vcluster -n my-vcluster --server=my-vcluster.example.com
vcluster connect my-vcluster -n my-vcluster --server=https://my-vcluster.example.com
```

Access the vcluster:
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/operator/external-datastore.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ vcluster:
- mountPath: /path/to
name: datastore-tls
volumes:
- name: foo
- name: datastore-tls
secret:
secretName: my-datastore-secret
items:
Expand Down
8 changes: 6 additions & 2 deletions pkg/controllers/resources/nodes/nodeservice/node_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand All @@ -25,7 +26,9 @@ var (
// ServiceNodeLabel specifies which node this service represents
ServiceNodeLabel = "vcluster.loft.sh/node"
// KubeletPort is the port we pretend the kubelet is running under
KubeletPort = int32(8443)
KubeletPort = int32(10250)
// KubeletTargetPort is the port vcluster will run under
KubeletTargetPort = 8443
)

type NodeServiceProvider interface {
Expand Down Expand Up @@ -175,7 +178,8 @@ func (n *nodeServiceProvider) GetNodeIP(ctx context.Context, name types.Namespac
Spec: corev1.ServiceSpec{
Ports: []corev1.ServicePort{
{
Port: int32(KubeletPort),
Port: int32(KubeletPort),
TargetPort: intstr.FromInt(KubeletTargetPort),
},
},
Selector: labelSelector,
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/filters/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,5 @@ func IsKubeletStats(path string) bool {
}

func IsKubeletMetrics(path string) bool {
return strings.HasSuffix(path, "/metrics/cadvisor") || strings.HasSuffix(path, "/metrics/probes") || strings.HasSuffix(path, "/metrics/resource") || strings.HasSuffix(path, "/metrics/resource/v1alpha1") || strings.HasSuffix(path, "/metrics/resource/v1beta1")
return strings.HasSuffix(path, "/metrics") || strings.HasSuffix(path, "/metrics/cadvisor") || strings.HasSuffix(path, "/metrics/probes") || strings.HasSuffix(path, "/metrics/resource") || strings.HasSuffix(path, "/metrics/resource/v1alpha1") || strings.HasSuffix(path, "/metrics/resource/v1beta1")
}

0 comments on commit 856f6d3

Please sign in to comment.