forked from kyma-project/infrastructure-manager
-
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.
- Loading branch information
Showing
8 changed files
with
144 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package v1_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
imv1 "github.com/kyma-project/infrastructure-manager/api/v1" | ||
"github.com/stretchr/testify/assert" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func Test_Runtime_IsControlledByProvisioner(t *testing.T) { | ||
var tests = []struct { | ||
desc string | ||
rt imv1.Runtime | ||
expected bool | ||
}{ | ||
{ | ||
desc: "rt without labels (zero value) should be controlled by the provisioner", | ||
rt: imv1.Runtime{}, | ||
expected: true, | ||
}, | ||
{ | ||
desc: "rt without labels (empty map) should be controlled by the provisioner", | ||
rt: imv1.Runtime{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Labels: map[string]string{}, | ||
}, | ||
}, | ||
expected: true, | ||
}, | ||
{ | ||
desc: fmt.Sprintf(`rt without label: "%s" should be controlled by the provisioner`, imv1.LabelControlledByProvisioner), | ||
rt: imv1.Runtime{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Labels: map[string]string{"test": "me"}, | ||
}, | ||
}, | ||
expected: true, | ||
}, | ||
{ | ||
desc: fmt.Sprintf(`rt with label: "%s=true" should be controlled by the provisioner`, imv1.LabelControlledByProvisioner), | ||
rt: imv1.Runtime{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Labels: map[string]string{imv1.LabelControlledByProvisioner: "true"}, | ||
}, | ||
}, | ||
expected: true, | ||
}, | ||
{ | ||
desc: fmt.Sprintf(`rt with label: "%s=sth" should be controlled by the provisioner`, imv1.LabelControlledByProvisioner), | ||
rt: imv1.Runtime{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Labels: map[string]string{imv1.LabelControlledByProvisioner: "sth"}, | ||
}, | ||
}, | ||
expected: true, | ||
}, | ||
{ | ||
desc: fmt.Sprintf(`rt with label: "%s=false" should NOT be controlled by the provisioner`, imv1.LabelControlledByProvisioner), | ||
rt: imv1.Runtime{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Labels: map[string]string{imv1.LabelControlledByProvisioner: "false"}, | ||
}, | ||
}, | ||
expected: false, | ||
}, | ||
} | ||
|
||
for i, tt := range tests { | ||
t.Run(fmt.Sprintf("%02d", i), func(t *testing.T) { | ||
actual := tt.rt.IsControlledByProvisioner() | ||
assert.Equal(t, tt.expected, actual, tt.desc) | ||
}) | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
internal/controller/runtime/fsm/runtime_fsm_create_shoot_dry_run.go
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,40 @@ | ||
package fsm | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
imv1 "github.com/kyma-project/infrastructure-manager/api/v1" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
) | ||
|
||
func sFnCreateShootDryRun(_ context.Context, m *fsm, s *systemState) (stateFn, *ctrl.Result, error) { | ||
m.log.Info("Create shoot [dry-run]") | ||
|
||
newShoot, err := convertShoot(&s.instance, m.ConverterConfig) | ||
if err != nil { | ||
m.log.Error(err, "Failed to convert Runtime instance to shoot object [dry-run]") | ||
return updateStatePendingWithErrorAndStop( | ||
&s.instance, | ||
imv1.ConditionTypeRuntimeProvisioned, | ||
imv1.ConditionReasonConversionError, | ||
"Runtime conversion error") | ||
} | ||
|
||
s.shoot = &newShoot | ||
s.instance.UpdateStateReady( | ||
imv1.ConditionTypeRuntimeProvisioned, | ||
imv1.ConditionReasonConfigurationCompleted, | ||
"Runtime processing completed successfully [dry-run]") | ||
|
||
// stop machine if persistence not enabled | ||
if m.PVCPath == "" { | ||
return updateStatusAndStop() | ||
} | ||
|
||
path := fmt.Sprintf("%s/%s-%s.yaml", m.PVCPath, s.shoot.Namespace, s.shoot.Name) | ||
if err := persist(path, s.shoot, m.writerProvider); err != nil { | ||
return updateStatusAndStopWithError(err) | ||
} | ||
return updateStatusAndStop() | ||
} |
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