-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Replica Override to manually scale a component (#665)
* Use Replica Override to manually scale a component * parse component status * make readable * handle missing k8s deployment * simplify code * use component pods instead of all pods * Deprecate and add reset-scale endpoints * refactor component status * reafctor environment, aux resources, component spec * bugfixes * bugfixesuse status from component, not auxiliar service * upadte tests * Update api/deployments/models/component_deployment.go Co-authored-by: Sergey Smolnikov <ssmol@equinor.com> * Update api/environments/component_handler.go Co-authored-by: Sergey Smolnikov <ssmol@equinor.com> * Update api/deployments/models/component_status.go Co-authored-by: Sergey Smolnikov <ssmol@equinor.com> * Update api/deployments/models/component_status.go Co-authored-by: Sergey Smolnikov <ssmol@equinor.com> * Update api/deployments/models/component_status.go Co-authored-by: Sergey Smolnikov <ssmol@equinor.com> * Update api/deployments/models/component_status.go Co-authored-by: Sergey Smolnikov <ssmol@equinor.com> * fix panic in tests * fix lint bugs * Update api/environments/environment_handler.go Co-authored-by: Sergey Smolnikov <ssmol@equinor.com> * Update api/environments/environment_handler.go Co-authored-by: Sergey Smolnikov <ssmol@equinor.com> * remove unused function * Add documentation * return err if deployment not found * Update api/utils/predicate/kubernetes.go Co-authored-by: Sergey Smolnikov <ssmol@equinor.com> * update swagger * remove outdated null check * remove outdated test, introduce WithComponentStatuserFunc * Test component actions with status * revert go 1.23 * cleanup unused code * update radix-operator --------- Co-authored-by: Sergey Smolnikov <ssmol@equinor.com>
- Loading branch information
Showing
28 changed files
with
801 additions
and
1,055 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package models_test | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/equinor/radix-api/api/deployments/models" | ||
radixutils "github.com/equinor/radix-common/utils" | ||
"github.com/equinor/radix-common/utils/pointers" | ||
operatordefaults "github.com/equinor/radix-operator/pkg/apis/defaults" | ||
"github.com/equinor/radix-operator/pkg/apis/kube" | ||
radixv1 "github.com/equinor/radix-operator/pkg/apis/radix/v1" | ||
"github.com/stretchr/testify/assert" | ||
appsv1 "k8s.io/api/apps/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestNoKubeDeployments_IsReconciling(t *testing.T) { | ||
status := models.ComponentStatusFromDeployment(&radixv1.RadixDeployComponent{}, nil, nil) | ||
assert.Equal(t, models.ComponentReconciling, status) | ||
} | ||
|
||
func TestKubeDeploymentsWithRestartLabel_IsRestarting(t *testing.T) { | ||
status := models.ComponentStatusFromDeployment( | ||
&radixv1.RadixDeployComponent{EnvironmentVariables: map[string]string{operatordefaults.RadixRestartEnvironmentVariable: radixutils.FormatTimestamp(time.Now())}}, | ||
createKubeDeployment(0), | ||
&radixv1.RadixDeployment{ | ||
ObjectMeta: metav1.ObjectMeta{Generation: 2}, | ||
Status: radixv1.RadixDeployStatus{Reconciled: metav1.NewTime(time.Now().Add(-10 * time.Minute))}, | ||
}) | ||
|
||
assert.Equal(t, models.ComponentRestarting, status) | ||
} | ||
|
||
func TestKubeDeploymentsWithoutReplicas_IsStopped(t *testing.T) { | ||
status := models.ComponentStatusFromDeployment( | ||
&radixv1.RadixDeployComponent{}, | ||
createKubeDeployment(0), | ||
&radixv1.RadixDeployment{ | ||
ObjectMeta: metav1.ObjectMeta{Generation: 1}, | ||
}) | ||
assert.Equal(t, models.StoppedComponent, status) | ||
} | ||
|
||
func TestKubeDeployment_IsConsistent(t *testing.T) { | ||
status := models.ComponentStatusFromDeployment( | ||
&radixv1.RadixDeployComponent{}, | ||
createKubeDeployment(1), | ||
&radixv1.RadixDeployment{ | ||
ObjectMeta: metav1.ObjectMeta{Generation: 1}, | ||
}) | ||
assert.Equal(t, models.ConsistentComponent, status) | ||
} | ||
|
||
func TestKubeDeployment_IsOutdated(t *testing.T) { | ||
status := models.ComponentStatusFromDeployment( | ||
&radixv1.RadixDeployComponent{}, | ||
createKubeDeployment(1), | ||
&radixv1.RadixDeployment{ | ||
ObjectMeta: metav1.ObjectMeta{Generation: 2}, | ||
}) | ||
assert.Equal(t, models.ComponentOutdated, status) | ||
} | ||
|
||
func createKubeDeployment(replicas int32) *appsv1.Deployment { | ||
return &appsv1.Deployment{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "helloworld", | ||
Annotations: map[string]string{kube.RadixDeploymentObservedGeneration: "1"}, | ||
OwnerReferences: []metav1.OwnerReference{{Controller: pointers.Ptr(true)}}}, | ||
Spec: appsv1.DeploymentSpec{Replicas: pointers.Ptr[int32](replicas)}, | ||
} | ||
} |
Oops, something went wrong.