Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,13 @@ setup-kind: ## Set up a Kind cluster for development if it does not exist
.PHONY: teardown-kind
teardown-kind: ## Tear down the Kind cluster, registry, and clean up images
# Delete the Kind cluster
$(KIND) delete cluster --name=$(DEV_KIND_CLUSTER)
$(KIND) delete cluster --name=$(DEV_KIND_CLUSTER) || { \
echo "Failed to delete cluster normally. Attempting manual cleanup..."; \
echo "Removing container $(DEV_KIND_CLUSTER)-control-plane directly..."; \
$(CONTAINER_TOOL) rm -f $(DEV_KIND_CLUSTER)-control-plane || true; \
echo "Retrying cluster deletion..."; \
$(KIND) delete cluster --name=$(DEV_KIND_CLUSTER) || echo "Cluster deletion completed with manual cleanup"; \
}
# Stop and remove registry container if running
$(CONTAINER_TOOL) stop registry || true
$(CONTAINER_TOOL) rm registry || true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
{{- if .Values.githubRbac.create }}
# This is the same ClusterRole as in group-clusterrole.yaml
# But we reference it separately for clarity in the RBAC structure
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: github-orgs-auth-whoami
annotations:
description: "Allows users to check their identity and permissions with commands like 'kubectl auth whoami' and 'kubectl auth can-i'"
rules:
# Allow users to check who they are authenticated as
- apiGroups: ["authentication.k8s.io"]
resources: ["selfsubjectreviews"]
verbs: ["create"]
# Allow users to check what permissions they have
- apiGroups: ["authorization.k8s.io"]
resources: ["selfsubjectaccessreviews", "selfsubjectrulesreviews"]
verbs: ["create"]
# This ClusterRole is now defined in group-clusterrole.yaml to avoid duplicate resource error
# user-clusterrolebinding.yaml will reference the ClusterRole defined there
{{- end }}
107 changes: 107 additions & 0 deletions internal/extensionapi/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package extensionapi

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("ExtensionConfig", func() {

Context("NewConfig", func() {
It("Should generate a config with defaults when no overrides are passed to the builder", func() {
config := NewConfig()

Expect(config.ApiPath).To(Equal(DefaultApiPath))
Expect(config.ServerPort).To(Equal(DefaultServerPort))
Expect(config.CertPath).To(Equal(DefaultCertPath))
Expect(config.KeyPath).To(Equal(DefaultKeyPath))
Expect(config.LogLevel).To(Equal(DefaultLogLevel))
Expect(config.DisableTLS).To(BeFalse())
Expect(config.ReadTimeoutSeconds).To(Equal(DefaultReadTimeoutSeconds))
Expect(config.WriteTimeoutSeconds).To(Equal(DefaultWriteTimeoutSeconds))
Expect(config.AllowedOrigin).To(Equal(DefaultAllowedOrigin))
})

It("Should chain overrides", func() {
config := NewConfig(
WithDefaultApiPath("/custom/api"),
WithServerPort(8080),
WithLogLevel("debug"),
)

Expect(config.ApiPath).To(Equal("/custom/api"))
Expect(config.ServerPort).To(Equal(8080))
Expect(config.LogLevel).To(Equal("debug"))

// Other fields should maintain defaults
Expect(config.CertPath).To(Equal(DefaultCertPath))
Expect(config.KeyPath).To(Equal(DefaultKeyPath))
Expect(config.DisableTLS).To(BeFalse())
Expect(config.ReadTimeoutSeconds).To(Equal(DefaultReadTimeoutSeconds))
Expect(config.WriteTimeoutSeconds).To(Equal(DefaultWriteTimeoutSeconds))
Expect(config.AllowedOrigin).To(Equal(DefaultAllowedOrigin))
})

It("Should allow to override ApiPath", func() {
customApiPath := "/custom/api/v2"
config := NewConfig(WithDefaultApiPath(customApiPath))

Expect(config.ApiPath).To(Equal(customApiPath))
})

It("Should allow to override DefaultServerPort", func() {
customPort := 9000
config := NewConfig(WithServerPort(customPort))

Expect(config.ServerPort).To(Equal(customPort))
})

It("Should allow to override DefaultCertPath", func() {
customPath := "/custom/cert/path.crt"
config := NewConfig(WithCertPath(customPath))

Expect(config.CertPath).To(Equal(customPath))
})

It("Should allow to override DefaultKeyPath", func() {
customPath := "/custom/key/path.key"
config := NewConfig(WithKeyPath(customPath))

Expect(config.KeyPath).To(Equal(customPath))
})

It("Should allow to override DefaultLogLevel", func() {
customLevel := "debug"
config := NewConfig(WithLogLevel(customLevel))

Expect(config.LogLevel).To(Equal(customLevel))
})

It("Should allow to override DefaultDisableTLS", func() {
config := NewConfig(WithDisableTLS(true))

Expect(config.DisableTLS).To(BeTrue())
})

It("Should allow to override DefaultReadTimeoutSeconds", func() {
customTimeout := 60
config := NewConfig(WithReadTimeoutSeconds(customTimeout))

Expect(config.ReadTimeoutSeconds).To(Equal(customTimeout))
})

It("Should allow to override DefaultWriteTimeoutSeconds", func() {
customTimeout := 240
config := NewConfig(WithWriteTimeoutSeconds(customTimeout))

Expect(config.WriteTimeoutSeconds).To(Equal(customTimeout))
})

It("Should allow to override DefaultAllowedOrigin", func() {
customOrigin := "https://example.com"
config := NewConfig(WithAllowedOrigin(customOrigin))

Expect(config.AllowedOrigin).To(Equal(customOrigin))
})
})
})
75 changes: 75 additions & 0 deletions internal/extensionapi/logging_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package extensionapi

import (
"context"

"github.com/go-logr/logr"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("Logging", func() {
var (
ctx context.Context
logger logr.Logger
)

BeforeEach(func() {
ctx = context.Background()
// Create a simple logr.Logger implementation
logger = logr.Discard()
})

Context("AddLoggerToContext", func() {
It("Should add the logger, and return the modified context", func() {
newCtx := AddLoggerToContext(ctx, logger)

// Check the contexts are different
Expect(newCtx).NotTo(BeIdenticalTo(ctx))

// Retrieve the logger from the context
retrievedLogger := newCtx.Value(loggerKey{})
Expect(retrievedLogger).NotTo(BeNil())
})

It("Should support a nil context value", func() {
// Create a nil logger value
var nilLogger logr.Logger

newCtx := AddLoggerToContext(ctx, nilLogger)

// Check the contexts are different
Expect(newCtx).NotTo(BeIdenticalTo(ctx))

// The key should exist in the context, but the value can be zero-valued
Expect(newCtx.Value(loggerKey{})).To(BeZero())
})
})

Context("GetLoggerFromContext", func() {
It("Should return the logger when available in context", func() {
// Add a logger to the context
ctxWithLogger := AddLoggerToContext(ctx, logger)

// Retrieve the logger using the function
retrievedLogger := GetLoggerFromContext(ctxWithLogger)

// The retrieved logger should not be nil
Expect(retrievedLogger).NotTo(BeNil())
})

It("Should return a discarding logger when not available in context", func() {
// Use a context without a logger
retrievedLogger := GetLoggerFromContext(ctx)

// The retrieved logger should not be nil (it should be a discard logger)
Expect(retrievedLogger).NotTo(BeNil())

// We can't directly check if it's a discard logger, but we can
// verify it doesn't panic when used
Expect(func() {
retrievedLogger.Info("This should be discarded")
}).NotTo(Panic())
})
})
})
Loading