-
Notifications
You must be signed in to change notification settings - Fork 340
/
create.go
84 lines (69 loc) · 2.58 KB
/
create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package integrationplatform
import (
"context"
corev1 "k8s.io/api/core/v1"
ctrl "sigs.k8s.io/controller-runtime/pkg/client"
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
"github.com/apache/camel-k/v2/pkg/install"
"github.com/apache/camel-k/v2/pkg/resources"
"github.com/apache/camel-k/v2/pkg/util/defaults"
)
// NewCreateAction returns the action that creates resources needed by the platform.
func NewCreateAction() Action {
return &createAction{}
}
type createAction struct {
baseAction
}
func (action *createAction) Name() string {
return "create"
}
func (action *createAction) CanHandle(platform *v1.IntegrationPlatform) bool {
return platform.Status.Phase == v1.IntegrationPlatformPhaseCreating
}
func (action *createAction) Handle(ctx context.Context, platform *v1.IntegrationPlatform) (*v1.IntegrationPlatform, error) {
paths, err := resources.WithPrefix("/resources/camel-catalog-")
if err != nil {
return nil, err
}
for _, k := range paths {
action.L.Infof("Installing camel catalog: %s", k)
err := install.Resources(ctx, action.client, platform.Namespace, true,
func(object ctrl.Object) ctrl.Object {
action.L.Infof("Copying platform annotations to catalog: %s", object.GetName())
object.SetAnnotations(platform.Annotations)
return object
},
k)
if err != nil {
return nil, err
}
}
if defaults.InstallDefaultKamelets() {
// Kamelet Catalog installed on platform reconciliation for cases where users install a global operator
if err := install.KameletCatalog(ctx, action.client, platform.Namespace); err != nil {
return nil, err
}
}
platform.Status.SetCondition(
v1.IntegrationPlatformConditionTypeCreated,
corev1.ConditionTrue,
v1.IntegrationPlatformConditionCreatedReason,
"integration platform created")
platform.Status.Phase = v1.IntegrationPlatformPhaseReady
return platform, nil
}