Skip to content

Commit

Permalink
Update devcontainer config
Browse files Browse the repository at this point in the history
  • Loading branch information
bells17 committed Apr 27, 2024
1 parent c9f4f0d commit 364df68
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 40 deletions.
63 changes: 39 additions & 24 deletions .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"
}
31 changes: 26 additions & 5 deletions .devcontainer/setup.sh 100644 → 100755
@@ -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.
Expand All @@ -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
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
35 changes: 24 additions & 11 deletions .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).
For details about kubetest2, see https://github.com/kubernetes-sigs/kubetest2.

0 comments on commit 364df68

Please sign in to comment.