From 364df68b7fbc0f03a65087095ab36ee5fb6dd322 Mon Sep 17 00:00:00 2001 From: bells17 Date: Sat, 27 Apr 2024 17:08:58 +0000 Subject: [PATCH] Update devcontainer config --- .devcontainer/devcontainer.json | 63 +++++++++++++++++++------------ .devcontainer/setup.sh | 31 ++++++++++++--- .devcontainer/welcome-message.txt | 35 +++++++++++------ 3 files changed, 89 insertions(+), 40 deletions(-) mode change 100644 => 100755 .devcontainer/setup.sh diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 1caae8bf36d7f..60ffbefeda64e 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,27 +1,42 @@ // For format details, see https://containers.dev { - "name": "Kubernetes environment from dev container", - // Image to pull when not building from scratch. See .devcontainer/build/devcontainer.json - // and .github/devcontainer-build-and-push.yml for the instructions on how this image is built - "image": "registry.k8s.io/build-image/kube-cross:v1.29.0-go1.21.3-bullseye.0", - // Setup the go environment and mount into the dev container at the expected location - "workspaceFolder": "/go/src/k8s.io/kubernetes", - "workspaceMount": "source=${localWorkspaceFolder},target=/go/src/k8s.io/kubernetes,type=bind,consistency=cached", - // Ensure that the host machine has enough resources to build and test Kubernetes - // "hack/verify-typecheck.sh" test requires more CPUs, ensure you have larger machine type (e.g. 16 cores) to pass this test - "hostRequirements": { - "cpus": 4 - }, - // Copy over welcome message and install pyyaml - "onCreateCommand": "bash .devcontainer/setup.sh", - // for Kubernetes testing, suppress extraneous forwarding messages - "otherPortsAttributes": { - "onAutoForward": "silent" - }, - "remoteUser": "root" - // Configure tool-specific properties. - // "customizations": { - // }, - // Use 'forwardPorts' to make a list of ports inside the container available locally. - // "forwardPorts": [], + "name": "Kubernetes environment from dev container", + + // For details about this image: + // https://github.com/kubernetes/release/tree/master/images/build/cross + "image": "registry.k8s.io/build-image/kube-cross:v1.30.0-go1.22.2-bullseye.0", + + // Setup the go environment and mount into the dev container at the expected location + "workspaceFolder": "/go/src/k8s.io/kubernetes", + "workspaceMount": "source=${localWorkspaceFolder},target=/go/src/k8s.io/kubernetes,type=bind,consistency=cached", + + // Features to add to the dev container. More info: https://containers.dev/features + "features": { + "ghcr.io/devcontainers/features/common-utils:2": {}, + "ghcr.io/devcontainers/features/docker-in-docker:2": {}, + "ghcr.io/devcontainers/features/python:1": {} + }, + + // Ensure that the host machine has enough resources to build and test Kubernetes + // "hack/verify-typecheck.sh" test requires more CPUs, ensure you have larger machine type (e.g. 16 cores) to pass this test if you use codespaces + // https://github.com/kubernetes/community/blob/master/contributors/devel/development.md#hardware-requirements + "hostRequirements": { + "memory": "8gb", + "storage": "50gb" + }, + + // Copy over welcome message and setup upstream + "onCreateCommand": "./.devcontainer/setup.sh", + + // for Kubernetes testing, suppress extraneous forwarding messages + "otherPortsAttributes": { + "onAutoForward": "silent" + }, + + // Add etcd path to PATH + "remoteEnv": { + "PATH": "${containerEnv:PATH}:${containerEnv:GOPATH}/src/k8s.io/kubernetes/third_party/etcd" + }, + + "remoteUser": "root" } \ No newline at end of file diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh old mode 100644 new mode 100755 index 02e859ceaa64c..bfe7f0d91d4cd --- a/.devcontainer/setup.sh +++ b/.devcontainer/setup.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# Copyright 2023 The Kubernetes Authors. +# Copyright 2024 The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -16,11 +16,32 @@ set -eux - - # Copies over welcome message +mkdir -p /usr/local/etc/vscode-dev-containers cp .devcontainer/welcome-message.txt /usr/local/etc/vscode-dev-containers/first-run-notice.txt -git remote add upstream https://github.com/kubernetes/kubernetes.git +# Ensure that the upstream remote is set, and configure it if it's not +if ! git remote | grep -q "^upstream$"; then + git remote add upstream https://github.com/kubernetes/kubernetes.git +else + if [ "$(git remote get-url upstream)" != "https://github.com/kubernetes/kubernetes.git" ]; then + git remote set-url upstream https://github.com/kubernetes/kubernetes.git + fi +fi + # Never push to upstream master -git remote set-url --push upstream no_push \ No newline at end of file +git remote set-url --push upstream no_push + +# Install gcloud command +curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key --keyring /usr/share/keyrings/cloud.google.gpg add - +echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | tee -a /etc/apt/sources.list.d/google-cloud-sdk.list +apt-get update +apt-get install -yq google-cloud-cli +rm -f /etc/apt/sources.list.d/google-cloud-sdk.list + +# Install PyYAML +pip3 install pyyaml + +# Install kind & kubetest2 for e2e testing +go install sigs.k8s.io/kind@latest +go install sigs.k8s.io/kubetest2/...@latest diff --git a/.devcontainer/welcome-message.txt b/.devcontainer/welcome-message.txt index 8072daf3f35f4..9703b06bbb930 100644 --- a/.devcontainer/welcome-message.txt +++ b/.devcontainer/welcome-message.txt @@ -1,20 +1,33 @@ 👋 Welcome to Kubernetes contribution in a dev container! - Works in GitHub Codespaces, VS Code, or in docker using the devcontainer cli + Works in GitHub Codespaces, VS Code, or in docker using the devcontainer cli. -See https://www.kubernetes.dev/docs/onboarding/ for guidance on contributing to Kuberentes +See https://www.kubernetes.dev/docs/onboarding/ for guidance on contributing to Kubernetes. -This debian dev container image satisfies https://github.com/kubernetes/community/blob/master/contributors/devel/development.md and includes: +This dev container environment satisfies the requirements found at https://github.com/kubernetes/community/blob/master/contributors/devel/development.md. and includes: - kubernetes/kubernetes repository - Docker - - go - - kubectl, etcd, kubetest2, and kind -For details about dev containers and the debian dev container base image see https://containers.dev and https://github.com/devcontainers/images/tree/main/src/base-debian. -The configuration for the dev container is in the .github/.devcontainer folder. (will be moved to prow) + - Go + - build-essential/rsync/jq/gcloud/PyYAML/etcd + - kind/kubetest2 + +For details about dev containers and the container image, see https://containers.dev and https://github.com/kubernetes/release/tree/master/images/build/cross. +The configuration for the dev container is in the .github/.devcontainer folder. 🎵 By default in Codespaces this environment uses a 4-core machine. Some tests may require a larger machine. In Codespaces you can change the machine type. See https://docs.github.com/en/codespaces/customizing-your-codespace/changing-the-machine-type-for-your-codespace -⚙️ If you are working in Codespaces on your own fork, this environment is automatically configured to support the GitHub - workflow https://www.kubernetes.dev/docs/guide/github-workflow/ (omit the clone step) -↪️ Otherwise Codespaces will automatically fork the repository for you when you make your first push +⚙️ If you are working in Codespaces on your own fork, this environment is automatically configured to support the GitHub workflow https://www.kubernetes.dev/docs/guide/github-workflow/. (omit the clone step) +↪️ Otherwise Codespaces will automatically fork the repository for you when you make your first push. + +🔍 To explore VS Code to its fullest, search using the Command Palette (Cmd/Ctrl + Shift + P or F1). + +🤖 Run e2e test command example: + kubetest2 kind -v 2 \ + --build \ + --up \ + --down \ + --test=ginkgo \ + -- \ + --use-built-binaries \ + --focus-regex='\[Conformance\]' -🔍 To explore VS Code to its fullest, search using the Command Palette (Cmd/Ctrl + Shift + P or F1). \ No newline at end of file +For details about kubetest2, see https://github.com/kubernetes-sigs/kubetest2.