Skip to content
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

Release radix-api #644

Merged
merged 1 commit into from
Jun 25, 2024
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
36 changes: 26 additions & 10 deletions api/deployments/models/component_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/equinor/radix-operator/pkg/apis/defaults"
"github.com/equinor/radix-operator/pkg/apis/deployment"
"github.com/equinor/radix-operator/pkg/apis/ingress"
v1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
radixv1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
"github.com/equinor/radix-operator/pkg/apis/utils"
)

Expand All @@ -21,11 +21,12 @@ type ComponentBuilder interface {
WithSchedulerPort(schedulerPort *int32) ComponentBuilder
WithScheduledJobPayloadPath(scheduledJobPayloadPath string) ComponentBuilder
WithRadixEnvironmentVariables(map[string]string) ComponentBuilder
WithComponent(v1.RadixCommonDeployComponent) ComponentBuilder
WithComponent(radixv1.RadixCommonDeployComponent) ComponentBuilder
WithAuxiliaryResource(AuxiliaryResource) ComponentBuilder
WithNotifications(*v1.Notifications) ComponentBuilder
WithNotifications(*radixv1.Notifications) ComponentBuilder
WithHorizontalScalingSummary(*HorizontalScalingSummary) ComponentBuilder
WithExternalDNS(externalDNS []ExternalDNS) ComponentBuilder
WithRuntime(*radixv1.Runtime) ComponentBuilder
BuildComponentSummary() (*ComponentSummary, error)
BuildComponent() (*Component, error)
}
Expand All @@ -51,7 +52,8 @@ type componentBuilder struct {
errors []error
commitID string
gitTags string
resources *v1.ResourceRequirements
resources *radixv1.ResourceRequirements
runtime *radixv1.Runtime
}

func (b *componentBuilder) WithStatus(status ComponentStatus) ComponentBuilder {
Expand Down Expand Up @@ -89,13 +91,14 @@ func (b *componentBuilder) WithAuxiliaryResource(auxResource AuxiliaryResource)
return b
}

func (b *componentBuilder) WithComponent(component v1.RadixCommonDeployComponent) ComponentBuilder {
func (b *componentBuilder) WithComponent(component radixv1.RadixCommonDeployComponent) ComponentBuilder {
b.componentName = component.GetName()
b.componentType = string(component.GetType())
b.componentImage = component.GetImage()
b.resources = component.GetResources()
b.commitID = component.GetEnvironmentVariables()[defaults.RadixCommitHashEnvironmentVariable]
b.gitTags = component.GetEnvironmentVariables()[defaults.RadixGitTagsEnvironmentVariable]
b.runtime = component.GetRuntime()

ports := []Port{}
if component.GetPorts() != nil {
Expand All @@ -113,11 +116,11 @@ func (b *componentBuilder) WithComponent(component v1.RadixCommonDeployComponent
for _, volumeMount := range component.GetVolumeMounts() {
volumeMountType := deployment.GetCsiAzureVolumeMountType(&volumeMount)
switch volumeMountType {
case v1.MountTypeBlob:
case radixv1.MountTypeBlob:
secretName := defaults.GetBlobFuseCredsSecretName(component.GetName(), volumeMount.Name)
b.secrets = append(b.secrets, secretName+defaults.BlobFuseCredsAccountKeyPartSuffix)
b.secrets = append(b.secrets, secretName+defaults.BlobFuseCredsAccountNamePartSuffix)
case v1.MountTypeBlobFuse2FuseCsiAzure, v1.MountTypeBlobFuse2Fuse2CsiAzure, v1.MountTypeBlobFuse2NfsCsiAzure, v1.MountTypeAzureFileCsiAzure:
case radixv1.MountTypeBlobFuse2FuseCsiAzure, radixv1.MountTypeBlobFuse2Fuse2CsiAzure, radixv1.MountTypeBlobFuse2NfsCsiAzure, radixv1.MountTypeAzureFileCsiAzure:
secretName := defaults.GetCsiAzureVolumeMountCredsSecretName(component.GetName(), volumeMount.Name)
b.secrets = append(b.secrets, secretName+defaults.CsiAzureCredsAccountKeyPartSuffix)
b.secrets = append(b.secrets, secretName+defaults.CsiAzureCredsAccountNamePartSuffix)
Expand Down Expand Up @@ -150,7 +153,7 @@ func (b *componentBuilder) WithComponent(component v1.RadixCommonDeployComponent
b.secrets = append(b.secrets, component.GetName()+suffix.OAuth2ClientSecret)
b.secrets = append(b.secrets, component.GetName()+suffix.OAuth2CookieSecret)

if oauth2.SessionStoreType == v1.SessionStoreRedis {
if oauth2.SessionStoreType == radixv1.SessionStoreRedis {
b.secrets = append(b.secrets, component.GetName()+suffix.OAuth2RedisPassword)
}
}
Expand All @@ -174,7 +177,7 @@ func (b *componentBuilder) WithComponent(component v1.RadixCommonDeployComponent
return b
}

func (b *componentBuilder) WithNotifications(notifications *v1.Notifications) ComponentBuilder {
func (b *componentBuilder) WithNotifications(notifications *radixv1.Notifications) ComponentBuilder {
if notifications == nil {
b.notifications = nil
return b
Expand All @@ -195,6 +198,11 @@ func (b *componentBuilder) WithExternalDNS(externalDNS []ExternalDNS) ComponentB
return b
}

func (b *componentBuilder) WithRuntime(runtime *radixv1.Runtime) ComponentBuilder {
b.runtime = runtime
return b
}

func (b *componentBuilder) buildError() error {
if len(b.errors) == 0 {
return nil
Expand All @@ -203,13 +211,20 @@ func (b *componentBuilder) buildError() error {
return errors.Join(b.errors...)
}

func (b *componentBuilder) buildRuntimeModel() *Runtime {
return &Runtime{
Architecture: utils.GetArchitectureFromRuntime(b.runtime),
}
}

func (b *componentBuilder) BuildComponentSummary() (*ComponentSummary, error) {
summary := ComponentSummary{
Name: b.componentName,
Type: b.componentType,
Image: b.componentImage,
CommitID: b.commitID,
GitTags: b.gitTags,
Runtime: b.buildRuntimeModel(),
}
if b.resources != nil && (len(b.resources.Limits) > 0 || len(b.resources.Requests) > 0) {
summary.Resources = pointers.Ptr(ConvertRadixResourceRequirements(*b.resources))
Expand All @@ -218,7 +233,7 @@ func (b *componentBuilder) BuildComponentSummary() (*ComponentSummary, error) {
}

func (b *componentBuilder) BuildComponent() (*Component, error) {
variables := v1.EnvVarsMap{}
variables := radixv1.EnvVarsMap{}
for name, value := range b.environmentVariables {
variables[name] = value
}
Expand Down Expand Up @@ -246,6 +261,7 @@ func (b *componentBuilder) BuildComponent() (*Component, error) {
HorizontalScalingSummary: b.hpa,
CommitID: variables[defaults.RadixCommitHashEnvironmentVariable],
GitTags: variables[defaults.RadixGitTagsEnvironmentVariable],
Runtime: b.buildRuntimeModel(),
}
if b.resources != nil && (len(b.resources.Limits) > 0 || len(b.resources.Requests) > 0) {
component.Resources = pointers.Ptr(ConvertRadixResourceRequirements(*b.resources))
Expand Down
14 changes: 14 additions & 0 deletions api/deployments/models/component_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ type Component struct {
//
// required: false
Resources *ResourceRequirements `json:"resources,omitempty"`

// Runtime requirements for the component or job
Runtime *Runtime `json:"runtime,omitempty"`
}

// ExternalDNS describes an external DNS entry for a component
Expand Down Expand Up @@ -275,6 +278,9 @@ type ComponentSummary struct {
//
// required: false
Resources *ResourceRequirements `json:"resources,omitempty"`

// Runtime requirements for the component or job
Runtime *Runtime `json:"runtime,omitempty"`
}

// ReplicaType The replica type
Expand Down Expand Up @@ -502,6 +508,14 @@ type ResourceRequirements struct {
Requests Resources `json:"requests,omitempty"`
}

// Runtime requirements for the component or job
type Runtime struct {
// CPU architecture
//
// example: amd64
Architecture string `json:"architecture"`
}

func GetReplicaSummary(pod corev1.Pod, lastEventWarning string) ReplicaSummary {
replicaSummary := ReplicaSummary{
Type: getReplicaType(pod).String(),
Expand Down
81 changes: 43 additions & 38 deletions api/deployments/models/deployment_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"testing"
"time"

"github.com/equinor/radix-operator/pkg/apis/defaults"
"github.com/equinor/radix-operator/pkg/apis/utils"

radixutils "github.com/equinor/radix-common/utils"
"github.com/equinor/radix-operator/pkg/apis/kube"
v1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
radixv1 "github.com/equinor/radix-operator/pkg/apis/radix/v1"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -22,23 +23,25 @@ func Test_DeploymentBuilder_BuildDeploymentSummary(t *testing.T) {
t.Parallel()

b := NewDeploymentBuilder().WithRadixDeployment(
&v1.RadixDeployment{
&radixv1.RadixDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: deploymentName,
Labels: map[string]string{kube.RadixJobNameLabel: jobName},
},
Spec: v1.RadixDeploymentSpec{
Spec: radixv1.RadixDeploymentSpec{
Environment: envName,
Components: []v1.RadixDeployComponent{
Components: []radixv1.RadixDeployComponent{
{Name: "comp1", Image: "comp_image1"},
{Name: "comp2", Image: "comp_image2"},
{Name: "comp2", Image: "comp_image2", Runtime: &radixv1.Runtime{Architecture: radixv1.RuntimeArchitectureArm64}},
{Name: "comp3", Image: "comp_image3", Node: radixv1.RadixNode{Gpu: "anygpu", GpuCount: "3"}},
},
Jobs: []v1.RadixDeployJobComponent{
Jobs: []radixv1.RadixDeployJobComponent{
{Name: "job1", Image: "job_image1"},
{Name: "job2", Image: "job_image2"},
{Name: "job2", Image: "job_image2", Runtime: &radixv1.Runtime{Architecture: radixv1.RuntimeArchitectureArm64}},
{Name: "job3", Image: "job_image3", Node: radixv1.RadixNode{Gpu: "anygpu", GpuCount: "3"}},
},
},
Status: v1.RadixDeployStatus{
Status: radixv1.RadixDeployStatus{
ActiveFrom: metav1.NewTime(activeFrom),
ActiveTo: metav1.NewTime(activeTo),
},
Expand All @@ -56,10 +59,12 @@ func Test_DeploymentBuilder_BuildDeploymentSummary(t *testing.T) {
CreatedByJob: jobName,
},
Components: []*ComponentSummary{
{Name: "comp1", Image: "comp_image1", Type: string(v1.RadixComponentTypeComponent)},
{Name: "comp2", Image: "comp_image2", Type: string(v1.RadixComponentTypeComponent)},
{Name: "job1", Image: "job_image1", Type: string(v1.RadixComponentTypeJob)},
{Name: "job2", Image: "job_image2", Type: string(v1.RadixComponentTypeJob)},
{Name: "comp1", Image: "comp_image1", Type: string(radixv1.RadixComponentTypeComponent), Runtime: &Runtime{Architecture: defaults.DefaultNodeSelectorArchitecture}},
{Name: "comp2", Image: "comp_image2", Type: string(radixv1.RadixComponentTypeComponent), Runtime: &Runtime{Architecture: string(radixv1.RuntimeArchitectureArm64)}},
{Name: "comp3", Image: "comp_image3", Type: string(radixv1.RadixComponentTypeComponent), Runtime: &Runtime{Architecture: defaults.DefaultNodeSelectorArchitecture}},
{Name: "job1", Image: "job_image1", Type: string(radixv1.RadixComponentTypeJob), Runtime: &Runtime{Architecture: defaults.DefaultNodeSelectorArchitecture}},
{Name: "job2", Image: "job_image2", Type: string(radixv1.RadixComponentTypeJob), Runtime: &Runtime{Architecture: string(radixv1.RuntimeArchitectureArm64)}},
{Name: "job3", Image: "job_image3", Type: string(radixv1.RadixComponentTypeJob), Runtime: &Runtime{Architecture: defaults.DefaultNodeSelectorArchitecture}},
},
}
assert.Equal(t, expected, actual)
Expand All @@ -68,16 +73,16 @@ func Test_DeploymentBuilder_BuildDeploymentSummary(t *testing.T) {
t.Run("build with pipeline job info", func(t *testing.T) {
t.Parallel()
b := NewDeploymentBuilder().WithPipelineJob(
&v1.RadixJob{
&radixv1.RadixJob{
ObjectMeta: metav1.ObjectMeta{
Name: jobName,
},
Spec: v1.RadixJobSpec{
PipeLineType: v1.BuildDeploy,
Build: v1.RadixBuildSpec{
Spec: radixv1.RadixJobSpec{
PipeLineType: radixv1.BuildDeploy,
Build: radixv1.RadixBuildSpec{
CommitID: commitID,
},
Promote: v1.RadixPromoteSpec{
Promote: radixv1.RadixPromoteSpec{
FromEnvironment: promoteFromEnv,
},
},
Expand All @@ -89,7 +94,7 @@ func Test_DeploymentBuilder_BuildDeploymentSummary(t *testing.T) {
DeploymentSummaryPipelineJobInfo: DeploymentSummaryPipelineJobInfo{
CreatedByJob: jobName,
CommitID: commitID,
PipelineJobType: string(v1.BuildDeploy),
PipelineJobType: string(radixv1.BuildDeploy),
PromotedFromEnvironment: promoteFromEnv,
},
}
Expand All @@ -99,27 +104,27 @@ func Test_DeploymentBuilder_BuildDeploymentSummary(t *testing.T) {
t.Run("deploy specific components", func(t *testing.T) {
t.Parallel()
b := NewDeploymentBuilder().WithPipelineJob(
&v1.RadixJob{
&radixv1.RadixJob{
ObjectMeta: metav1.ObjectMeta{
Name: jobName,
},
Spec: v1.RadixJobSpec{
PipeLineType: v1.Deploy,
Deploy: v1.RadixDeploySpec{
Spec: radixv1.RadixJobSpec{
PipeLineType: radixv1.Deploy,
Deploy: radixv1.RadixDeploySpec{
ToEnvironment: "dev",
CommitID: commitID,
ComponentsToDeploy: []string{"comp1", "job1"},
},
},
},
).WithRadixDeployment(&v1.RadixDeployment{
).WithRadixDeployment(&radixv1.RadixDeployment{
ObjectMeta: metav1.ObjectMeta{Name: "rd1"},
Spec: v1.RadixDeploymentSpec{
Components: []v1.RadixDeployComponent{
Spec: radixv1.RadixDeploymentSpec{
Components: []radixv1.RadixDeployComponent{
{Name: "comp1"},
{Name: "comp2"},
},
Jobs: []v1.RadixDeployJobComponent{
Jobs: []radixv1.RadixDeployJobComponent{
{Name: "job1"},
{Name: "job2"},
},
Expand Down Expand Up @@ -157,16 +162,16 @@ func Test_DeploymentBuilder_BuildDeployment(t *testing.T) {
t.Parallel()

b := NewDeploymentBuilder().WithRadixDeployment(
&v1.RadixDeployment{
&radixv1.RadixDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: deploymentName,
Namespace: deploymentNamespace,
Labels: map[string]string{kube.RadixJobNameLabel: jobName},
},
Spec: v1.RadixDeploymentSpec{
Spec: radixv1.RadixDeploymentSpec{
Environment: envName,
},
Status: v1.RadixDeployStatus{
Status: radixv1.RadixDeployStatus{
ActiveFrom: metav1.NewTime(activeFrom),
ActiveTo: metav1.NewTime(activeTo),
},
Expand All @@ -193,13 +198,13 @@ func Test_DeploymentBuilder_BuildDeployment(t *testing.T) {
b := NewDeploymentBuilder().
WithRadixRegistration(rr).
WithPipelineJob(
&v1.RadixJob{
&radixv1.RadixJob{
ObjectMeta: metav1.ObjectMeta{
Name: jobName,
},
Spec: v1.RadixJobSpec{
PipeLineType: v1.Deploy,
Deploy: v1.RadixDeploySpec{
Spec: radixv1.RadixJobSpec{
PipeLineType: radixv1.Deploy,
Deploy: radixv1.RadixDeploySpec{
ToEnvironment: "dev",
ComponentsToDeploy: []string{"comp1", "job1"},
},
Expand All @@ -211,24 +216,24 @@ func Test_DeploymentBuilder_BuildDeployment(t *testing.T) {
{Name: "job1"},
{Name: "job2"},
}).WithRadixDeployment(
&v1.RadixDeployment{
&radixv1.RadixDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: deploymentName,
Namespace: deploymentNamespace,
Labels: map[string]string{kube.RadixJobNameLabel: jobName},
},
Spec: v1.RadixDeploymentSpec{
Spec: radixv1.RadixDeploymentSpec{
Environment: envName,
Components: []v1.RadixDeployComponent{
Components: []radixv1.RadixDeployComponent{
{Name: "comp1"},
{Name: "comp2"},
},
Jobs: []v1.RadixDeployJobComponent{
Jobs: []radixv1.RadixDeployJobComponent{
{Name: "job1"},
{Name: "job2"},
},
},
Status: v1.RadixDeployStatus{
Status: radixv1.RadixDeployStatus{
ActiveFrom: metav1.NewTime(activeFrom),
ActiveTo: metav1.NewTime(activeTo),
},
Expand Down
3 changes: 3 additions & 0 deletions api/deployments/models/scheduled_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ type ScheduledJobSummary struct {
// required: false
Node *Node `json:"node,omitempty"`

// Runtime requirements for the batch job
Runtime *Runtime `json:"runtime,omitempty"`

// DeploymentName name of RadixDeployment for the job
//
// required: false
Expand Down
Loading
Loading