Skip to content

Commit

Permalink
add support for profiling service and ingress in armada components (#330
Browse files Browse the repository at this point in the history
)

Signed-off-by: Dejan Zele Pejchev <[email protected]>
  • Loading branch information
dejanzele authored Oct 8, 2024
1 parent 9bc9036 commit 98e12f9
Show file tree
Hide file tree
Showing 53 changed files with 1,935 additions and 1,558 deletions.
4 changes: 3 additions & 1 deletion api/install/v1alpha1/armadaserver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ type ArmadaServerSpec struct {
Replicas *int32 `json:"replicas,omitempty"`
// NodeSelector restricts the ArmadaServer pod to run on nodes matching the configured selectors
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// Ingress defines labels and annotations for the Ingress controller of ArmadaServer
// Ingress defines configuration for the Ingress resource
Ingress *IngressConfig `json:"ingress,omitempty"`
// ProfilingIngressConfig defines configuration for the profiling Ingress resource
ProfilingIngressConfig *IngressConfig `json:"profilingIngressConfig,omitempty"`
// An array of host names to build ingress rules for
HostNames []string `json:"hostNames,omitempty"`
// Who is issuing certificates for CA
Expand Down
2 changes: 2 additions & 0 deletions api/install/v1alpha1/binoculars_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ type BinocularsSpec struct {
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// Ingress for this component. Used to inject labels/annotations into ingress
Ingress *IngressConfig `json:"ingress,omitempty"`
// ProfilingIngressConfig defines configuration for the profiling Ingress resource
ProfilingIngressConfig *IngressConfig `json:"profilingIngressConfig,omitempty"`
// An array of host names to build ingress rules for
HostNames []string `json:"hostNames,omitempty"`
// Who is issuing certificates for CA
Expand Down
52 changes: 4 additions & 48 deletions api/install/v1alpha1/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/yaml"
)

const (
defaultHTTPPort = 8080
defaultGRPCPort = 50051
defaultMetricsPort = 9000
)

type Image struct {
Expand Down Expand Up @@ -62,23 +55,17 @@ type IngressConfig struct {
Annotations map[string]string `json:"annotations,omitempty"`
// The type of ingress that is used
IngressClass string `json:"ingressClass,omitempty"`
// Overide name for ingress
NameOverride string `json:"nameOverride,omitempty"`
// An array of host names to build ingress rules for
Hostnames []string `json:"hostNames,omitempty"`
// Who is issuing certificates for CA
ClusterIssuer string `json:"clusterIssuer,omitempty"`
}

type AdditionalClusterRoleBinding struct {
NameSuffix string `json:"nameSuffix"`
ClusterRoleName string `json:"clusterRoleName"`
}

type PortConfig struct {
HttpPort int32 `json:"httpPort"`
HttpNodePort int32 `json:"httpNodePort,omitempty"`
GrpcPort int32 `json:"grpcPort"`
GrpcNodePort int32 `json:"grpcNodePort,omitempty"`
MetricsPort int32 `json:"metricsPort"`
}

// CommonSpecBase is the common configuration for all services.
// NOTE(Clif): You must label this with `json:""` when using it as an embedded
// struct in order for controller-gen to use the promoted fields as expected.
Expand Down Expand Up @@ -109,37 +96,6 @@ type CommonSpecBase struct {
AdditionalVolumes []corev1.Volume `json:"additionalVolumes,omitempty"`
// Additional volume mounts that are added as volumes
AdditionalVolumeMounts []corev1.VolumeMount `json:"additionalVolumeMounts,omitempty"`
// PortConfig is automatically populated with defaults and overlaid by values in ApplicationConfig.
PortConfig PortConfig `json:"portConfig,omitempty"`
}

// BuildPortConfig extracts ports from the ApplicationConfig and returns a PortConfig
func BuildPortConfig(rawAppConfig runtime.RawExtension) (PortConfig, error) {
appConfig, err := ConvertRawExtensionToYaml(rawAppConfig)
if err != nil {
return PortConfig{}, err
}
// defaults
portConfig := PortConfig{
HttpPort: defaultHTTPPort,
GrpcPort: defaultGRPCPort,
MetricsPort: defaultMetricsPort,
}
err = yaml.Unmarshal([]byte(appConfig), &portConfig)
if err != nil {
return PortConfig{}, err
}
return portConfig, nil
}

// ConvertRawExtensionToYaml converts a RawExtension input to Yaml
func ConvertRawExtensionToYaml(config runtime.RawExtension) (string, error) {
yamlConfig, err := yaml.JSONToYAML(config.Raw)
if err != nil {
return "", err
}

return string(yamlConfig), nil
}

func GetDefaultSecurityContext() *corev1.SecurityContext {
Expand Down
104 changes: 0 additions & 104 deletions api/install/v1alpha1/common_test.go
Original file line number Diff line number Diff line change
@@ -1,105 +1 @@
package v1alpha1

import (
"testing"

"github.com/stretchr/testify/assert"

"k8s.io/apimachinery/pkg/runtime"
)

func TestBuildPortConfig(t *testing.T) {
tests := []struct {
name string
input runtime.RawExtension
expected PortConfig
wantErr bool
}{
{
name: "it provides some reasonable defaults",
input: runtime.RawExtension{Raw: []byte(`{ }`)},
expected: PortConfig{
HttpPort: 8080,
GrpcPort: 50051,
MetricsPort: 9000,
},
},
{
name: "it errors with bad json (so does everything else in the app)",
input: runtime.RawExtension{Raw: []byte(`{"httpPort": 8081`)},
expected: PortConfig{},
wantErr: true,
},
{
name: "it accepts partial overrides from the config",
input: runtime.RawExtension{Raw: []byte(`{"httpPort": 8081}`)},
expected: PortConfig{
HttpPort: 8081,
GrpcPort: 50051,
MetricsPort: 9000,
},
},
{
name: "it accepts complete override from the config",
input: runtime.RawExtension{
Raw: []byte(`{"httpPort": 8081, "grpcPort": 50052, "metricsPort": 9001 }`),
},
expected: PortConfig{
HttpPort: 8081,
GrpcPort: 50052,
MetricsPort: 9001,
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
pc, err := BuildPortConfig(tt.input)
if tt.wantErr {
assert.Error(t, err)
} else {
assert.Nil(t, err)
}
assert.Equal(t, tt.expected, pc)
})
}
}

func TestConvertRawExtensionToYaml(t *testing.T) {

tests := []struct {
name string
input runtime.RawExtension
expected string
wantErr bool
}{
{
name: "it converts runtime.RawExtension json to yaml",
input: runtime.RawExtension{Raw: []byte(`{ "test": { "foo": "bar" }}`)},
expected: "test:\n foo: bar\n",
},
{
name: "it converts complex runtime.RawExtension json to yaml",
input: runtime.RawExtension{Raw: []byte(`{ "test": {"foo": "bar"}, "test1": {"foo1": { "foo2": "bar2" }}}`)},
expected: "test:\n foo: bar\ntest1:\n foo1:\n foo2: bar2\n",
},
{
name: "it errors if runtime.RawExtension raw is malformed json",
input: runtime.RawExtension{Raw: []byte(`{ "foo": "bar" `)},
expected: "",
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
output, err := ConvertRawExtensionToYaml(tt.input)
if tt.wantErr {
assert.Error(t, err)
} else {
assert.Nil(t, err)
}
assert.Equal(t, tt.expected, output)
})
}
}
2 changes: 2 additions & 0 deletions api/install/v1alpha1/eventingester_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type EventIngesterSpec struct {
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
// PodSecurityContext defines the security options the pod should be run with
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
// ProfilingIngressConfig defines configuration for the profiling Ingress resource
ProfilingIngressConfig *IngressConfig `json:"profilingIngressConfig,omitempty"`
}

// EventIngesterStatus defines the observed state of EventIngester
Expand Down
2 changes: 2 additions & 0 deletions api/install/v1alpha1/executor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ type ExecutorSpec struct {
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
// PodSecurityContext defines the security options the pod should be run with
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
// ProfilingIngressConfig defines configuration for the profiling Ingress resource
ProfilingIngressConfig *IngressConfig `json:"profilingIngressConfig,omitempty"`
}

// ExecutorStatus defines the observed state of Executor
Expand Down
2 changes: 2 additions & 0 deletions api/install/v1alpha1/lookout_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ type LookoutSpec struct {
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
// PodSecurityContext defines the security options the pod should be run with
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
// ProfilingIngressConfig defines configuration for the profiling Ingress resource
ProfilingIngressConfig *IngressConfig `json:"profilingIngressConfig,omitempty"`
}

// LookoutStatus defines the observed state of lookout
Expand Down
2 changes: 2 additions & 0 deletions api/install/v1alpha1/lookoutingester_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type LookoutIngesterSpec struct {
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
// PodSecurityContext defines the security options the pod should be run with
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
// ProfilingIngressConfig defines configuration for the profiling Ingress resource
ProfilingIngressConfig *IngressConfig `json:"profilingIngressConfig,omitempty"`
}

// LookoutIngesterStatus defines the observed state of LookoutIngester
Expand Down
2 changes: 2 additions & 0 deletions api/install/v1alpha1/scheduler_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type SchedulerSpec struct {
Replicas *int32 `json:"replicas,omitempty"`
// Ingress defines labels and annotations for the Ingress controller of Scheduler
Ingress *IngressConfig `json:"ingress,omitempty"`
// ProfilingIngressConfig defines configuration for the profiling Ingress resource
ProfilingIngressConfig *IngressConfig `json:"profilingIngressConfig,omitempty"`
// An array of host names to build ingress rules for
HostNames []string `json:"hostNames,omitempty"`
// Who is issuing certificates for CA
Expand Down
2 changes: 2 additions & 0 deletions api/install/v1alpha1/scheduleringester_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type SchedulerIngesterSpec struct {
SecurityContext *corev1.SecurityContext `json:"securityContext,omitempty"`
// PodSecurityContext defines the security options the pod should be run with
PodSecurityContext *corev1.PodSecurityContext `json:"podSecurityContext,omitempty"`
// ProfilingIngressConfig defines configuration for the profiling Ingress resource
ProfilingIngressConfig *IngressConfig `json:"profilingIngressConfig,omitempty"`
}

// SchedulerIngesterStatus defines the observed state of SchedulerIngester
Expand Down
61 changes: 45 additions & 16 deletions api/install/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 98e12f9

Please sign in to comment.