Skip to content

Commit

Permalink
chore: moves authz config struct
Browse files Browse the repository at this point in the history
Follow up to #70 where I missed that PlatformAuthzConfig struct was in
ctrl pkg. This PR moves it to authz pkg, so it's placed similarly to its
routing counter-part.
  • Loading branch information
bartoszmajsak committed Sep 3, 2024
1 parent 288ffb4 commit 0553750
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 27 deletions.
13 changes: 2 additions & 11 deletions controllers/authzctrl/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
const name = "authorization"

func New(cli client.Client, log logr.Logger,
protectedResource platform.ProtectedResource, config PlatformAuthorizationConfig) *Controller {
protectedResource platform.ProtectedResource, config authorization.ProviderConfig) *Controller {
return &Controller{
active: true,
Client: cli,
Expand All @@ -45,21 +45,12 @@ func New(cli client.Client, log logr.Logger,
}
}

type PlatformAuthorizationConfig struct {
// Label in a format of key=value. It's used to target created AuthConfig by Authorino instance.
Label string
// Audiences is a list of audiences that will be used in the AuthConfig template when performing TokenReview.
Audiences []string
// ProviderName is the name of the registered external authorization provider in Service Mesh.
ProviderName string
}

// Controller holds the authorization controller configuration.
type Controller struct {
client.Client
active bool
log logr.Logger
config PlatformAuthorizationConfig
config authorization.ProviderConfig
protectedResource platform.ProtectedResource
typeDetector authorization.AuthTypeDetector
hostExtractor spi.HostExtractor
Expand Down
3 changes: 2 additions & 1 deletion controllers/authzctrl/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/opendatahub-io/odh-platform/controllers/authzctrl"
"github.com/opendatahub-io/odh-platform/pkg/authorization"
"github.com/opendatahub-io/odh-platform/pkg/config"
"github.com/opendatahub-io/odh-platform/pkg/platform"
"github.com/opendatahub-io/odh-platform/test"
Expand Down Expand Up @@ -47,7 +48,7 @@ var _ = SynchronizedBeforeSuite(func(ctx context.Context) {
Ports: []string{},
HostPaths: []string{"spec.host"},
},
authzctrl.PlatformAuthorizationConfig{
authorization.ProviderConfig{
Label: config.GetAuthorinoLabel(),
Audiences: config.GetAuthAudience(),
ProviderName: config.GetAuthProvider(),
Expand Down
4 changes: 2 additions & 2 deletions controllers/routingctrl/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const (
finalizerName = "routing.opendatahub.io/finalizer"
)

func New(cli client.Client, log logr.Logger, target platform.RoutingTarget, config routing.PlatformRoutingConfiguration) *Controller {
func New(cli client.Client, log logr.Logger, target platform.RoutingTarget, config routing.IngressConfig) *Controller {
return &Controller{
active: true,
Client: cli,
Expand All @@ -47,7 +47,7 @@ type Controller struct {
log logr.Logger
component platform.RoutingTarget
templateLoader routing.TemplateLoader
config routing.PlatformRoutingConfiguration
config routing.IngressConfig
}

// +kubebuilder:rbac:groups="route.openshift.io",resources=routes,verbs=*
Expand Down
2 changes: 1 addition & 1 deletion controllers/routingctrl/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (

var (
envTest *k8senvtest.Client
routingConfiguration = routing.PlatformRoutingConfiguration{
routingConfiguration = routing.IngressConfig{
IngressService: "odh-router",
GatewayNamespace: "odh-gateway",
IngressSelectorLabel: "istio",
Expand Down
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/opendatahub-io/odh-platform/controllers/authzctrl"
"github.com/opendatahub-io/odh-platform/controllers/routingctrl"
"github.com/opendatahub-io/odh-platform/pkg/authorization"
"github.com/opendatahub-io/odh-platform/pkg/config"
"github.com/opendatahub-io/odh-platform/pkg/platform"
"github.com/opendatahub-io/odh-platform/pkg/routing"
Expand Down Expand Up @@ -73,7 +74,7 @@ func main() {
os.Exit(1)
}

authorizationConfig := authzctrl.PlatformAuthorizationConfig{
authorizationConfig := authorization.ProviderConfig{
Label: config.GetAuthorinoLabel(),
Audiences: config.GetAuthAudience(),
ProviderName: config.GetAuthProvider(),
Expand All @@ -95,7 +96,7 @@ func main() {
os.Exit(1)
}

routingConfig := routing.PlatformRoutingConfiguration{
routingConfig := routing.IngressConfig{
IngressSelectorLabel: config.GetIngressSelectorKey(),
IngressSelectorValue: config.GetIngressSelectorValue(),
IngressService: config.GetGatewayService(),
Expand Down
11 changes: 11 additions & 0 deletions pkg/authorization/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ import (
"k8s.io/apimachinery/pkg/types"
)

// ProviderConfig holds the configuration for the authorization component as defined by the platform.
type ProviderConfig struct {
// Label in a format of key=value. It's used to target created AuthConfig by Authorino instance.
Label string
// Audiences is a list of audiences used in the AuthConfig template when performing TokenReview.
Audiences []string
// ProviderName is the name of the registered external authorization provider in Service Mesh.
ProviderName string
}

// AuthType represents the type of authentication to be used for a given resource.
type AuthType string

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/routing/routing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var _ = Describe("Resource functions", test.Unit(), func() {

Context("Template Loader", func() {

config := routing.PlatformRoutingConfiguration{
config := routing.IngressConfig{
GatewayNamespace: "opendatahub",
IngressSelectorLabel: "istio",
IngressSelectorValue: "rhoai-gateway",
Expand Down
22 changes: 13 additions & 9 deletions pkg/routing/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,34 @@ func UnusedRouteTypes(exportModes []RouteType) []RouteType {
return unused
}

type PlatformRoutingConfiguration struct {
// IngressConfig holds the configuration for the ingress resources (Istio Ingress Gateway services).
// These values determine how and where additional resources required for platform routing will be created.
type IngressConfig struct {
IngressSelectorLabel,
IngressSelectorValue,
IngressService,
GatewayNamespace string
}

// ExposedServiceConfig holds the configuration for a service that is used to serve as a cluster-local service facade
// allowing non-mesh clients to access mesh services.
type ExposedServiceConfig struct {
PlatformRoutingConfiguration
IngressConfig
PublicServiceName,
ServiceName,
ServiceNamespace,
ServiceTargetPort,
Domain string
}

func NewExposedServiceConfig(config PlatformRoutingConfiguration, svc *corev1.Service, domain string) *ExposedServiceConfig {
func NewExposedServiceConfig(config IngressConfig, svc *corev1.Service, domain string) *ExposedServiceConfig {
return &ExposedServiceConfig{
PlatformRoutingConfiguration: config,
PublicServiceName: svc.GetName() + "-" + svc.GetNamespace(),
ServiceName: svc.GetName(),
ServiceNamespace: svc.GetNamespace(),
ServiceTargetPort: svc.Spec.Ports[0].TargetPort.String(),
Domain: domain,
IngressConfig: config,
PublicServiceName: svc.GetName() + "-" + svc.GetNamespace(),
ServiceName: svc.GetName(),
ServiceNamespace: svc.GetNamespace(),
ServiceTargetPort: svc.Spec.Ports[0].TargetPort.String(),
Domain: domain,
}
}

Expand Down

0 comments on commit 0553750

Please sign in to comment.