|
| 1 | +//go:build e2e |
| 2 | + |
| 3 | +/* |
| 4 | +Copyright 2025 The KCP Authors. |
| 5 | +
|
| 6 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +you may not use this file except in compliance with the License. |
| 8 | +You may obtain a copy of the License at |
| 9 | +
|
| 10 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +
|
| 12 | +Unless required by applicable law or agreed to in writing, software |
| 13 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +See the License for the specific language governing permissions and |
| 16 | +limitations under the License. |
| 17 | +*/ |
| 18 | + |
| 19 | +package frontproxies |
| 20 | + |
| 21 | +import ( |
| 22 | + "context" |
| 23 | + "fmt" |
| 24 | + "testing" |
| 25 | + "time" |
| 26 | + |
| 27 | + "github.com/go-logr/logr" |
| 28 | + |
| 29 | + corev1 "k8s.io/api/core/v1" |
| 30 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 31 | + "k8s.io/apimachinery/pkg/types" |
| 32 | + ctrlruntime "sigs.k8s.io/controller-runtime" |
| 33 | + |
| 34 | + operatorv1alpha1 "github.com/kcp-dev/kcp-operator/sdk/apis/operator/v1alpha1" |
| 35 | + "github.com/kcp-dev/kcp-operator/test/utils" |
| 36 | +) |
| 37 | + |
| 38 | +func TestCreateFrontProxy(t *testing.T) { |
| 39 | + fmt.Println() |
| 40 | + |
| 41 | + ctrlruntime.SetLogger(logr.Discard()) |
| 42 | + |
| 43 | + client := utils.GetKubeClient(t) |
| 44 | + ctx := context.Background() |
| 45 | + namespace := "create-frontproxy" |
| 46 | + |
| 47 | + utils.CreateSelfDestructingNamespace(t, ctx, client, namespace) |
| 48 | + |
| 49 | + externalHostname := "front-proxy-front-proxy.svc.cluster.local" |
| 50 | + |
| 51 | + // deploy rootshard |
| 52 | + rootShard := utils.DeployRootShard(ctx, t, client, namespace, externalHostname) |
| 53 | + |
| 54 | + // deploy front-proxy |
| 55 | + frontProxy := utils.DeployFrontProxy(ctx, t, client, namespace, rootShard.Name, externalHostname) |
| 56 | + |
| 57 | + // create front-proxy kubeconfig |
| 58 | + configSecretName := "kubeconfig-front-proxy-e2e" |
| 59 | + |
| 60 | + fpConfig := operatorv1alpha1.Kubeconfig{} |
| 61 | + fpConfig.Name = "front-proxy" |
| 62 | + fpConfig.Namespace = namespace |
| 63 | + fpConfig.Spec = operatorv1alpha1.KubeconfigSpec{ |
| 64 | + Target: operatorv1alpha1.KubeconfigTarget{ |
| 65 | + FrontProxyRef: &corev1.LocalObjectReference{ |
| 66 | + Name: frontProxy.Name, |
| 67 | + }, |
| 68 | + }, |
| 69 | + Username: "e2e", |
| 70 | + Validity: metav1.Duration{Duration: 2 * time.Hour}, |
| 71 | + SecretRef: corev1.LocalObjectReference{ |
| 72 | + Name: configSecretName, |
| 73 | + }, |
| 74 | + Groups: []string{"system:masters"}, |
| 75 | + } |
| 76 | + |
| 77 | + t.Log("Creating kubeconfig for FrontProxy…") |
| 78 | + if err := client.Create(ctx, &fpConfig); err != nil { |
| 79 | + t.Fatal(err) |
| 80 | + } |
| 81 | + utils.WaitForObject(t, ctx, client, &corev1.Secret{}, types.NamespacedName{Namespace: fpConfig.Namespace, Name: fpConfig.Spec.SecretRef.Name}) |
| 82 | + |
| 83 | + // verify that we can use frontproxy kubeconfig to access rootshard workspaces |
| 84 | + t.Log("Connecting to FrontProxy…") |
| 85 | + kcpClient := utils.ConnectWithKubeconfig(t, ctx, client, namespace, fpConfig.Name) |
| 86 | + // proof of life: list something every logicalcluster in kcp has |
| 87 | + t.Log("Should be able to list Secrets.") |
| 88 | + secrets := &corev1.SecretList{} |
| 89 | + if err := kcpClient.List(ctx, secrets); err != nil { |
| 90 | + t.Fatalf("Failed to list secrets in kcp: %v", err) |
| 91 | + } |
| 92 | +} |
0 commit comments