Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

fix directly return when appconfig has multiple scope to attach #188

Merged
merged 1 commit into from
Aug 28, 2020
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
4 changes: 3 additions & 1 deletion pkg/controller/v1alpha2/applicationconfiguration/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ func (a *workloads) Apply(ctx context.Context, status []v1alpha2.WorkloadStatus,
}

for _, s := range wl.Scopes {
return a.applyScope(ctx, wl, s, workloadRef)
if err := a.applyScope(ctx, wl, s, workloadRef); err != nil {
return err
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestApplyWorkloads(t *testing.T) {
Namespace: namespace,
},
TypeMeta: metav1.TypeMeta{
APIVersion: "scope.oam.dev",
APIVersion: "scope.oam.dev/v1alpha2",
Kind: "scopeKind",
},
Spec: v1alpha2.HealthScopeSpec{
Expand Down Expand Up @@ -272,6 +272,10 @@ func TestApplyWorkloads(t *testing.T) {
client: resource.ApplyFn(func(_ context.Context, o runtime.Object, _ ...resource.ApplyOption) error { return nil }),
rawClient: &test.MockClient{
MockGet: func(_ context.Context, key client.ObjectKey, obj runtime.Object) error {
if scopeDef, ok := obj.(*v1alpha2.ScopeDefinition); ok {
*scopeDef = scopeDefinition
return nil
}
return nil
},
MockUpdate: func(ctx context.Context, obj runtime.Object, opts ...client.UpdateOption) error {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e-test/appconfig_finalizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (
workloadScopeFinalizer = "scope.finalizer.core.oam.dev"
)

var _ = Describe("Resource Dependency in an ApplicationConfiguration", func() {
var _ = Describe("Finalizer for HealthScope in ApplicationConfiguration", func() {
ctx := context.Background()
namespace := "finalizer-test"
ns := corev1.Namespace{
Expand Down
47 changes: 42 additions & 5 deletions test/e2e-test/health_scope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ var _ = Describe("HealthScope", func() {
logf.Log.Info("Creating component", "Name", comp.Name, "Namespace", comp.Namespace)
Expect(k8sClient.Create(ctx, &comp)).Should(BeNil())
// Create application configuration
workloadInstanceName := "example-appconfig-healthscope"
workloadInstanceName1 := "example-appconfig-healthscope-a"
workloadInstanceName2 := "example-appconfig-healthscope-b"
imageName := "wordpress:php7.2"
appConfig := v1alpha2.ApplicationConfiguration{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -191,7 +192,29 @@ var _ = Describe("HealthScope", func() {
ParameterValues: []v1alpha2.ComponentParameterValue{
{
Name: "instance-name",
Value: intstr.IntOrString{StrVal: workloadInstanceName, Type: intstr.String},
Value: intstr.IntOrString{StrVal: workloadInstanceName1, Type: intstr.String},
},
{
Name: "image",
Value: intstr.IntOrString{StrVal: imageName, Type: intstr.String},
},
},
Scopes: []v1alpha2.ComponentScope{
{
ScopeReference: v1alpha1.TypedReference{
APIVersion: gvks[0].GroupVersion().String(),
Kind: v1alpha2.HealthScopeGroupVersionKind.Kind,
Name: healthScopeName,
},
},
},
},
{
ComponentName: componentName,
ParameterValues: []v1alpha2.ComponentParameterValue{
{
Name: "instance-name",
Value: intstr.IntOrString{StrVal: workloadInstanceName2, Type: intstr.String},
},
{
Name: "image",
Expand All @@ -214,9 +237,9 @@ var _ = Describe("HealthScope", func() {
logf.Log.Info("Creating application config", "Name", appConfig.Name, "Namespace", appConfig.Namespace)
Expect(k8sClient.Create(ctx, &appConfig)).Should(BeNil())
// Verification
By("Checking deployment is created")
By("Checking deployment-a is created")
objectKey := client.ObjectKey{
Name: workloadInstanceName,
Name: workloadInstanceName1,
Namespace: namespace,
}
deploy := &appsv1.Deployment{}
Expand All @@ -227,6 +250,20 @@ var _ = Describe("HealthScope", func() {
},
time.Second*15, time.Millisecond*500).Should(BeNil())

// Verify all components declared in AppConfig are created
By("Checking deployment-b is created")
objectKey2 := client.ObjectKey{
Name: workloadInstanceName2,
Namespace: namespace,
}
deploy2 := &appsv1.Deployment{}
logf.Log.Info("Checking on deployment", "Key", objectKey2)
Eventually(
func() error {
return k8sClient.Get(ctx, objectKey2, deploy2)
},
time.Second*15, time.Millisecond*500).Should(BeNil())

By("Verify that the parameter substitute works")
Expect(deploy.Spec.Template.Spec.Containers[0].Image).Should(Equal(imageName))

Expand Down Expand Up @@ -261,6 +298,6 @@ var _ = Describe("HealthScope", func() {

return healthScope.Status.Health == "healthy"
},
time.Second*60, time.Second*5).Should(BeEquivalentTo(true))
time.Second*120, time.Second*5).Should(BeEquivalentTo(true))
})
})