Skip to content

Auto import kubernetes template in Helm charts #3550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix template problems
  • Loading branch information
deansheather committed Aug 25, 2022
commit 89c3f9966f0cf4809a68f8b2c4532bbc231589c5
4 changes: 1 addition & 3 deletions cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,6 @@ func Server(newAPI func(*coderd.Options) *coderd.API) *cobra.Command {
switch autoImportTemplate {
case "kubernetes":
v = coderd.AutoImportTemplateKubernetes
case "kubernetes-multi-service":
v = coderd.AutoImportTemplateKubernetesMultiService
default:
return xerrors.Errorf("auto import template %q is not supported", autoImportTemplate)
}
Expand Down Expand Up @@ -770,7 +768,7 @@ func Server(newAPI func(*coderd.Options) *coderd.API) *cobra.Command {
cliflag.BoolVarP(root.Flags(), &secureAuthCookie, "secure-auth-cookie", "", "CODER_SECURE_AUTH_COOKIE", false, "Specifies if the 'Secure' property is set on browser session cookies")
cliflag.StringVarP(root.Flags(), &sshKeygenAlgorithmRaw, "ssh-keygen-algorithm", "", "CODER_SSH_KEYGEN_ALGORITHM", "ed25519", "Specifies the algorithm to use for generating ssh keys. "+
`Accepted values are "ed25519", "ecdsa", or "rsa4096"`)
cliflag.StringArrayVarP(root.Flags(), &autoImportTemplates, "auto-import-template", "", "CODER_TEMPLATE_AUTOIMPORT", []string{}, "Which templates to auto-import. Available auto-importable templates are: kubernetes, kubernetes-multi-service")
cliflag.StringArrayVarP(root.Flags(), &autoImportTemplates, "auto-import-template", "", "CODER_TEMPLATE_AUTOIMPORT", []string{}, "Which templates to auto-import. Available auto-importable templates are: kubernetes")
cliflag.BoolVarP(root.Flags(), &spooky, "spooky", "", "", false, "Specifies spookiness level")
cliflag.BoolVarP(root.Flags(), &verbose, "verbose", "v", "CODER_VERBOSE", false, "Enables verbose logging.")
_ = root.Flags().MarkHidden("spooky")
Expand Down
3 changes: 1 addition & 2 deletions coderd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ var (
type AutoImportTemplate string

const (
AutoImportTemplateKubernetes AutoImportTemplate = "kubernetes"
AutoImportTemplateKubernetesMultiService AutoImportTemplate = "kubernetes-multi-service"
AutoImportTemplateKubernetes AutoImportTemplate = "kubernetes"
)

// Returns a single template.
Expand Down
6 changes: 3 additions & 3 deletions coderd/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,17 @@ func (api *API) postFirstUser(rw http.ResponseWriter, r *http.Request) {
// Determine which parameter values to use.
parameters := map[string]string{}
switch template {
case AutoImportTemplateKubernetes, AutoImportTemplateKubernetesMultiService:
case AutoImportTemplateKubernetes:

// Determine the current namespace we're in.
const namespaceFile = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"
namespace, err := os.ReadFile(namespaceFile)
if err != nil {
parameters["use_kubeconfig"] = "true" // use ~/.config/kubeconfig
parameters["workspaces_namespace"] = "coder-workspaces"
parameters["namespace"] = "coder-workspaces"
} else {
parameters["use_kubeconfig"] = "false" // use SA auth
parameters["workspaces_namespace"] = string(bytes.TrimSpace(namespace))
parameters["namespace"] = string(bytes.TrimSpace(namespace))
}

default:
Expand Down
8 changes: 3 additions & 5 deletions coderd/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func TestFirstUser(t *testing.T) {
// also added to the switch statement below.
autoImportTemplates := []coderd.AutoImportTemplate{
coderd.AutoImportTemplateKubernetes,
coderd.AutoImportTemplateKubernetesMultiService,
}
client := coderdtest.New(t, &coderdtest.Options{
AutoImportTemplates: autoImportTemplates,
Expand All @@ -77,10 +76,9 @@ func TestFirstUser(t *testing.T) {

templates, err := client.TemplatesByOrganization(ctx, u.OrganizationID)
require.NoError(t, err, "list templates")
require.Len(t, templates, 2, "should have two templates")
require.Len(t, templates, len(autoImportTemplates), "listed templates count does not match")
require.ElementsMatch(t, autoImportTemplates, []coderd.AutoImportTemplate{
coderd.AutoImportTemplate(templates[0].Name),
coderd.AutoImportTemplate(templates[1].Name),
}, "template names don't match")

for _, template := range templates {
Expand All @@ -91,9 +89,9 @@ func TestFirstUser(t *testing.T) {
// Ensure all template parameters are present.
expectedParams := map[string]bool{}
switch template.Name {
case "kubernetes", "kubernetes-multi-service":
case "kubernetes":
expectedParams["use_kubeconfig"] = false
expectedParams["workspaces_namespace"] = false
expectedParams["namespace"] = false
default:
t.Fatalf("unexpected template name %q", template.Name)
}
Expand Down
13 changes: 7 additions & 6 deletions enterprise/coderd/licenses.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var ValidMethods = []string{"EdDSA"}

// key20220812 is the Coder license public key with id 2022-08-12 used to validate licenses signed
// by our signing infrastructure
//
//go:embed keys/2022-08-12
var key20220812 []byte

Expand Down Expand Up @@ -134,12 +135,12 @@ func (a *licenseAPI) handler() http.Handler {
// postLicense adds a new Enterprise license to the cluster. We allow multiple different licenses
// in the cluster at one time for several reasons:
//
// 1. Upgrades --- if the license format changes from one version of Coder to the next, during a
// rolling update you will have different Coder servers that need different licenses to function.
// 2. Avoid abrupt feature breakage --- when an admin uploads a new license with different features
// we generally don't want the old features to immediately break without warning. With a grace
// period on the license, features will continue to work from the old license until its grace
// period, then the users will get a warning allowing them to gracefully stop using the feature.
// 1. Upgrades --- if the license format changes from one version of Coder to the next, during a
// rolling update you will have different Coder servers that need different licenses to function.
// 2. Avoid abrupt feature breakage --- when an admin uploads a new license with different features
// we generally don't want the old features to immediately break without warning. With a grace
// period on the license, features will continue to work from the old license until its grace
// period, then the users will get a warning allowing them to gracefully stop using the feature.
func (a *licenseAPI) postLicense(rw http.ResponseWriter, r *http.Request) {
if !a.auth.Authorize(r, rbac.ActionCreate, rbac.ResourceLicense) {
httpapi.Forbidden(rw)
Expand Down
111 changes: 0 additions & 111 deletions examples/templates/kubernetes-pod/README.md

This file was deleted.

118 changes: 0 additions & 118 deletions examples/templates/kubernetes-pod/main.tf

This file was deleted.

Loading