mirror of https://github.com/kubevela/kubevela.git
fix bug: application can not create component which contains namespace resource (#1920)
* align initializer's namespace to vela-system * fix makefile * fix terraform namespace * add test
This commit is contained in:
parent
ead859b717
commit
644cafe0a1
2
Makefile
2
Makefile
|
|
@ -153,6 +153,8 @@ e2e-setup:
|
|||
bin/vela addon enable fluxcd
|
||||
ginkgo version
|
||||
ginkgo -v -r e2e/setup
|
||||
|
||||
timeout 600s bash -c -- 'while true; do kubectl get ns flux-system; if [ $$? -eq 0 ] ; then break; else sleep 5; fi;done'
|
||||
kubectl wait --for=condition=Ready pod -l app.kubernetes.io/name=vela-core,app.kubernetes.io/instance=kubevela -n vela-system --timeout=600s
|
||||
kubectl wait --for=condition=Ready pod -l app=source-controller -n flux-system --timeout=600s
|
||||
kubectl wait --for=condition=Ready pod -l app=helm-controller -n flux-system --timeout=600s
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ data:
|
|||
annotations:
|
||||
addons.oam.dev/description: Flux is a set of continuous and progressive delivery solutions for Kubernetes
|
||||
name: fluxcd
|
||||
namespace: flux-system
|
||||
namespace: vela-system
|
||||
spec:
|
||||
appTemplate:
|
||||
spec:
|
||||
|
|
@ -4158,6 +4158,13 @@ data:
|
|||
- emptyDir: {}
|
||||
name: tmp
|
||||
type: raw
|
||||
- name: flux-system
|
||||
properties:
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: flux-system
|
||||
type: raw
|
||||
- name: allow-egress
|
||||
properties:
|
||||
apiVersion: networking.k8s.io/v1
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ data:
|
|||
annotations:
|
||||
addons.oam.dev/description: Kruise is a Kubernetes extended suite for application automations
|
||||
name: kruise
|
||||
namespace: kruise-system
|
||||
namespace: vela-system
|
||||
spec:
|
||||
appTemplate:
|
||||
spec:
|
||||
|
|
@ -58,6 +58,12 @@ data:
|
|||
rollingState: ""
|
||||
upgradedReadyReplicas: 0
|
||||
upgradedReplicas: 0
|
||||
dependsOn:
|
||||
- ref:
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: Initializer
|
||||
name: fluxcd
|
||||
namespace: vela-system
|
||||
status:
|
||||
observedGeneration: 0
|
||||
kind: ConfigMap
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ data:
|
|||
annotations:
|
||||
addons.oam.dev/description: ocm-cluster-manager can deploy an OCM hub cluster environment.
|
||||
name: ocm-cluster-manager
|
||||
namespace: open-cluster-management
|
||||
namespace: vela-system
|
||||
spec:
|
||||
appTemplate:
|
||||
spec:
|
||||
|
|
@ -176,6 +176,17 @@ data:
|
|||
name: cluster-manager-service-account
|
||||
namespace: open-cluster-management
|
||||
type: raw
|
||||
- name: cluster-manager-hub
|
||||
properties:
|
||||
apiVersion: operator.open-cluster-management.io/v1
|
||||
kind: ClusterManager
|
||||
metadata:
|
||||
name: cluster-manager-hub
|
||||
spec:
|
||||
placementImagePullSpec: quay.io/open-cluster-management/placement
|
||||
registrationImagePullSpec: quay.io/open-cluster-management/registration
|
||||
workImagePullSpec: quay.io/open-cluster-management/work
|
||||
type: raw
|
||||
- name: clustermanagers.operator.open-cluster-management.io
|
||||
properties:
|
||||
apiVersion: apiextensions.k8s.io/v1
|
||||
|
|
@ -333,16 +344,12 @@ data:
|
|||
conditions: []
|
||||
storedVersions: []
|
||||
type: raw
|
||||
- name: cluster-manager-hub
|
||||
- name: open-cluster-management
|
||||
properties:
|
||||
apiVersion: operator.open-cluster-management.io/v1
|
||||
kind: ClusterManager
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: cluster-manager-hub
|
||||
spec:
|
||||
placementImagePullSpec: registry.cn-beijing.aliyuncs.com/ocm/placement
|
||||
registrationImagePullSpec: registry.cn-beijing.aliyuncs.com/ocm/registration:latest
|
||||
workImagePullSpec: registry.cn-beijing.aliyuncs.com/ocm/work
|
||||
name: open-cluster-management
|
||||
type: raw
|
||||
- name: cluster-manager-controller
|
||||
properties:
|
||||
|
|
@ -388,7 +395,7 @@ data:
|
|||
- args:
|
||||
- /registration-operator
|
||||
- hub
|
||||
image: registry.cn-beijing.aliyuncs.com/ocm/registration-operator:latest
|
||||
image: quay.io/open-cluster-management/registration-operator:latest
|
||||
imagePullPolicy: IfNotPresent
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
|
|
|
|||
|
|
@ -7,18 +7,25 @@ data:
|
|||
annotations:
|
||||
addons.oam.dev/description: Terraform Controller is a Kubernetes Controller for Terraform.
|
||||
name: terraform
|
||||
namespace: tc-system
|
||||
namespace: vela-system
|
||||
spec:
|
||||
appTemplate:
|
||||
spec:
|
||||
components:
|
||||
- name: terraform-system
|
||||
properties:
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: terraform-system
|
||||
type: raw
|
||||
- name: terraform-controller-release
|
||||
properties:
|
||||
apiVersion: helm.toolkit.fluxcd.io/v2beta1
|
||||
kind: HelmRelease
|
||||
metadata:
|
||||
name: terraform-controller-release
|
||||
namespace: tc-system
|
||||
namespace: terraform-system
|
||||
spec:
|
||||
chart:
|
||||
spec:
|
||||
|
|
@ -27,7 +34,7 @@ data:
|
|||
sourceRef:
|
||||
kind: GitRepository
|
||||
name: terraform-controller-repo
|
||||
namespace: tc-system
|
||||
namespace: terraform-system
|
||||
interval: 5m
|
||||
values:
|
||||
replicaCount: 1
|
||||
|
|
@ -38,7 +45,7 @@ data:
|
|||
kind: GitRepository
|
||||
metadata:
|
||||
name: terraform-controller-repo
|
||||
namespace: tc-system
|
||||
namespace: terraform-system
|
||||
spec:
|
||||
interval: 5m
|
||||
ref:
|
||||
|
|
@ -58,7 +65,7 @@ data:
|
|||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: Initializer
|
||||
name: fluxcd
|
||||
namespace: flux-system
|
||||
namespace: vela-system
|
||||
status:
|
||||
observedGeneration: 0
|
||||
kind: ConfigMap
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||
package assemble
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
runtimev1alpha1 "github.com/crossplane/crossplane-runtime/apis/core/v1alpha1"
|
||||
|
|
@ -300,6 +301,13 @@ func (am *AppManifests) filterAndSetAnnotations(obj *unstructured.Unstructured)
|
|||
}
|
||||
|
||||
func (am *AppManifests) setNamespace(obj *unstructured.Unstructured) {
|
||||
|
||||
// we should not set namespace for namespace resources
|
||||
gvk := obj.GetObjectKind().GroupVersionKind()
|
||||
if gvk == corev1.SchemeGroupVersion.WithKind(reflect.TypeOf(corev1.Namespace{}).Name()) {
|
||||
return
|
||||
}
|
||||
|
||||
// only set app's namespace when namespace is unspecified
|
||||
// it's by design to set arbitrary namespace in render phase
|
||||
if len(obj.GetNamespace()) == 0 {
|
||||
|
|
|
|||
|
|
@ -219,4 +219,59 @@ var _ = Describe("Initializer Normal tests", func() {
|
|||
return nil
|
||||
}, 30*time.Second, 5*time.Second).Should(Succeed())
|
||||
})
|
||||
|
||||
It("Test apply initializer which will create namespace", func() {
|
||||
randomNs := randomNamespaceName("initializer-createns")
|
||||
init := &v1beta1.Initializer{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "Initializer",
|
||||
APIVersion: "core.oam.dev/v1beta1",
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "env4",
|
||||
Namespace: namespace,
|
||||
},
|
||||
Spec: v1beta1.InitializerSpec{
|
||||
AppTemplate: v1beta1.Application{
|
||||
Spec: v1beta1.ApplicationSpec{
|
||||
Components: []v1beta1.ApplicationComponent{
|
||||
{
|
||||
Name: randomNs,
|
||||
Type: "raw",
|
||||
Properties: util.Object2RawExtension(map[string]interface{}{
|
||||
"apiVersion": "v1",
|
||||
"kind": "Namespace",
|
||||
"metadata": map[string]interface{}{
|
||||
"name": randomNs,
|
||||
},
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
By("Create Initializer createNamespaceInit")
|
||||
Eventually(func() error {
|
||||
return k8sClient.Create(ctx, init)
|
||||
}, 10*time.Second, 500*time.Millisecond).Should(Succeed())
|
||||
|
||||
By("Verify the application is created successfully")
|
||||
app := new(v1beta1.Application)
|
||||
Eventually(func() error {
|
||||
return k8sClient.Get(ctx, client.ObjectKey{Name: init.Name, Namespace: namespace}, app)
|
||||
}, 60*time.Second, 2*time.Millisecond).Should(Succeed())
|
||||
|
||||
By("Verify the initializer env3 successfully initialized the environment")
|
||||
Eventually(func() error {
|
||||
err := k8sClient.Get(ctx, client.ObjectKey{Name: init.Name, Namespace: namespace}, init)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if init.Status.ObservedGeneration < init.Generation {
|
||||
return fmt.Errorf("environment was not successfully initialized")
|
||||
}
|
||||
return nil
|
||||
}, 30*time.Second, 5*time.Second).Should(Succeed())
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: flux-system
|
||||
name: vela-system
|
||||
spec: {}
|
||||
status: {}
|
||||
---
|
||||
|
|
@ -11,7 +11,7 @@ metadata:
|
|||
annotations:
|
||||
addons.oam.dev/description: Flux is a set of continuous and progressive delivery solutions for Kubernetes
|
||||
name: fluxcd
|
||||
namespace: flux-system
|
||||
namespace: vela-system
|
||||
spec:
|
||||
appTemplate:
|
||||
spec:
|
||||
|
|
@ -4162,6 +4162,13 @@ spec:
|
|||
- emptyDir: {}
|
||||
name: tmp
|
||||
type: raw
|
||||
- name: flux-system
|
||||
properties:
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: flux-system
|
||||
type: raw
|
||||
- name: allow-egress
|
||||
properties:
|
||||
apiVersion: networking.k8s.io/v1
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: kruise-system
|
||||
name: vela-system
|
||||
spec: {}
|
||||
status: {}
|
||||
---
|
||||
|
|
@ -11,7 +11,7 @@ metadata:
|
|||
annotations:
|
||||
addons.oam.dev/description: Kruise is a Kubernetes extended suite for application automations
|
||||
name: kruise
|
||||
namespace: kruise-system
|
||||
namespace: vela-system
|
||||
spec:
|
||||
appTemplate:
|
||||
spec:
|
||||
|
|
@ -62,5 +62,11 @@ spec:
|
|||
rollingState: ""
|
||||
upgradedReadyReplicas: 0
|
||||
upgradedReplicas: 0
|
||||
dependsOn:
|
||||
- ref:
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: Initializer
|
||||
name: fluxcd
|
||||
namespace: vela-system
|
||||
status:
|
||||
observedGeneration: 0
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: open-cluster-management
|
||||
name: vela-system
|
||||
spec: {}
|
||||
status: {}
|
||||
---
|
||||
|
|
@ -11,7 +11,7 @@ metadata:
|
|||
annotations:
|
||||
addons.oam.dev/description: ocm-cluster-manager can deploy an OCM hub cluster environment.
|
||||
name: ocm-cluster-manager
|
||||
namespace: open-cluster-management
|
||||
namespace: vela-system
|
||||
spec:
|
||||
appTemplate:
|
||||
spec:
|
||||
|
|
@ -180,6 +180,17 @@ spec:
|
|||
name: cluster-manager-service-account
|
||||
namespace: open-cluster-management
|
||||
type: raw
|
||||
- name: cluster-manager-hub
|
||||
properties:
|
||||
apiVersion: operator.open-cluster-management.io/v1
|
||||
kind: ClusterManager
|
||||
metadata:
|
||||
name: cluster-manager-hub
|
||||
spec:
|
||||
placementImagePullSpec: quay.io/open-cluster-management/placement
|
||||
registrationImagePullSpec: quay.io/open-cluster-management/registration
|
||||
workImagePullSpec: quay.io/open-cluster-management/work
|
||||
type: raw
|
||||
- name: clustermanagers.operator.open-cluster-management.io
|
||||
properties:
|
||||
apiVersion: apiextensions.k8s.io/v1
|
||||
|
|
@ -337,16 +348,12 @@ spec:
|
|||
conditions: []
|
||||
storedVersions: []
|
||||
type: raw
|
||||
- name: cluster-manager-hub
|
||||
- name: open-cluster-management
|
||||
properties:
|
||||
apiVersion: operator.open-cluster-management.io/v1
|
||||
kind: ClusterManager
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: cluster-manager-hub
|
||||
spec:
|
||||
placementImagePullSpec: registry.cn-beijing.aliyuncs.com/ocm/placement
|
||||
registrationImagePullSpec: registry.cn-beijing.aliyuncs.com/ocm/registration:latest
|
||||
workImagePullSpec: registry.cn-beijing.aliyuncs.com/ocm/work
|
||||
name: open-cluster-management
|
||||
type: raw
|
||||
- name: cluster-manager-controller
|
||||
properties:
|
||||
|
|
@ -392,7 +399,7 @@ spec:
|
|||
- args:
|
||||
- /registration-operator
|
||||
- hub
|
||||
image: registry.cn-beijing.aliyuncs.com/ocm/registration-operator:latest
|
||||
image: quay.io/open-cluster-management/registration-operator:latest
|
||||
imagePullPolicy: IfNotPresent
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: tc-system
|
||||
name: vela-system
|
||||
spec: {}
|
||||
status: {}
|
||||
---
|
||||
|
|
@ -11,18 +11,25 @@ metadata:
|
|||
annotations:
|
||||
addons.oam.dev/description: Terraform Controller is a Kubernetes Controller for Terraform.
|
||||
name: terraform
|
||||
namespace: tc-system
|
||||
namespace: vela-system
|
||||
spec:
|
||||
appTemplate:
|
||||
spec:
|
||||
components:
|
||||
- name: terraform-system
|
||||
properties:
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: terraform-system
|
||||
type: raw
|
||||
- name: terraform-controller-release
|
||||
properties:
|
||||
apiVersion: helm.toolkit.fluxcd.io/v2beta1
|
||||
kind: HelmRelease
|
||||
metadata:
|
||||
name: terraform-controller-release
|
||||
namespace: tc-system
|
||||
namespace: terraform-system
|
||||
spec:
|
||||
chart:
|
||||
spec:
|
||||
|
|
@ -31,7 +38,7 @@ spec:
|
|||
sourceRef:
|
||||
kind: GitRepository
|
||||
name: terraform-controller-repo
|
||||
namespace: tc-system
|
||||
namespace: terraform-system
|
||||
interval: 5m
|
||||
values:
|
||||
replicaCount: 1
|
||||
|
|
@ -42,7 +49,7 @@ spec:
|
|||
kind: GitRepository
|
||||
metadata:
|
||||
name: terraform-controller-repo
|
||||
namespace: tc-system
|
||||
namespace: terraform-system
|
||||
spec:
|
||||
interval: 5m
|
||||
ref:
|
||||
|
|
@ -62,6 +69,6 @@ spec:
|
|||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: Initializer
|
||||
name: fluxcd
|
||||
namespace: flux-system
|
||||
namespace: vela-system
|
||||
status:
|
||||
observedGeneration: 0
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: flux-system
|
||||
|
|
@ -4,7 +4,7 @@ metadata:
|
|||
annotations:
|
||||
addons.oam.dev/description: "Flux is a set of continuous and progressive delivery solutions for Kubernetes"
|
||||
name: fluxcd
|
||||
namespace: flux-system
|
||||
namespace: vela-system
|
||||
spec:
|
||||
appTemplate:
|
||||
spec:
|
||||
|
|
|
|||
|
|
@ -4,8 +4,14 @@ metadata:
|
|||
annotations:
|
||||
addons.oam.dev/description: "Kruise is a Kubernetes extended suite for application automations"
|
||||
name: kruise
|
||||
namespace: kruise-system
|
||||
namespace: vela-system
|
||||
spec:
|
||||
dependsOn:
|
||||
- ref:
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: Initializer
|
||||
name: fluxcd
|
||||
namespace: vela-system
|
||||
appTemplate:
|
||||
spec:
|
||||
components: {{ range .ResourceFiles }}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
apiVersion: operator.open-cluster-management.io/v1
|
||||
kind: ClusterManager
|
||||
metadata:
|
||||
name: cluster-manager-hub
|
||||
spec:
|
||||
registrationImagePullSpec: quay.io/open-cluster-management/registration
|
||||
workImagePullSpec: quay.io/open-cluster-management/work
|
||||
placementImagePullSpec: quay.io/open-cluster-management/placement
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
apiVersion: operator.open-cluster-management.io/v1
|
||||
kind: ClusterManager
|
||||
metadata:
|
||||
name: cluster-manager-hub
|
||||
spec:
|
||||
registrationImagePullSpec: registry.cn-beijing.aliyuncs.com/ocm/registration:latest
|
||||
workImagePullSpec: registry.cn-beijing.aliyuncs.com/ocm/work
|
||||
placementImagePullSpec: registry.cn-beijing.aliyuncs.com/ocm/placement
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: open-cluster-management
|
||||
|
|
@ -40,7 +40,7 @@ spec:
|
|||
- args:
|
||||
- /registration-operator
|
||||
- hub
|
||||
image: registry.cn-beijing.aliyuncs.com/ocm/registration-operator:latest
|
||||
image: quay.io/open-cluster-management/registration-operator:latest
|
||||
imagePullPolicy: IfNotPresent
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ metadata:
|
|||
annotations:
|
||||
addons.oam.dev/description: "ocm-cluster-manager can deploy an OCM hub cluster environment."
|
||||
name: ocm-cluster-manager
|
||||
namespace: open-cluster-management
|
||||
namespace: vela-system
|
||||
spec:
|
||||
appTemplate:
|
||||
spec:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,4 @@
|
|||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: terraform-system
|
||||
|
|
@ -2,7 +2,7 @@ apiVersion: helm.toolkit.fluxcd.io/v2beta1
|
|||
kind: HelmRelease
|
||||
metadata:
|
||||
name: terraform-controller-release
|
||||
namespace: tc-system
|
||||
namespace: terraform-system
|
||||
spec:
|
||||
interval: 5m
|
||||
chart:
|
||||
|
|
@ -11,7 +11,7 @@ spec:
|
|||
sourceRef:
|
||||
kind: GitRepository
|
||||
name: terraform-controller-repo
|
||||
namespace: tc-system
|
||||
namespace: terraform-system
|
||||
interval: 1m
|
||||
values:
|
||||
replicaCount: 1
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ apiVersion: source.toolkit.fluxcd.io/v1beta1
|
|||
kind: GitRepository
|
||||
metadata:
|
||||
name: terraform-controller-repo
|
||||
namespace: tc-system
|
||||
namespace: terraform-system
|
||||
spec:
|
||||
url: https://github.com/oam-dev/terraform-controller
|
||||
ref:
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@ metadata:
|
|||
annotations:
|
||||
addons.oam.dev/description: "Terraform Controller is a Kubernetes Controller for Terraform."
|
||||
name: terraform
|
||||
namespace: tc-system
|
||||
namespace: vela-system
|
||||
spec:
|
||||
dependsOn:
|
||||
- ref:
|
||||
apiVersion: core.oam.dev/v1beta1
|
||||
kind: Initializer
|
||||
name: fluxcd
|
||||
namespace: flux-system
|
||||
namespace: vela-system
|
||||
appTemplate:
|
||||
spec:
|
||||
components: {{ range .ResourceFiles }}
|
||||
|
|
|
|||
Loading…
Reference in New Issue