diff --git a/pkg/cmd/completion_bash.go b/pkg/cmd/completion_bash.go index ca8720d677..1606f12682 100644 --- a/pkg/cmd/completion_bash.go +++ b/pkg/cmd/completion_bash.go @@ -93,21 +93,21 @@ __kamel_kubectl_get_servicebinding() { local service_names local services_list local namespace_condition - + if command -v awk &> /dev/null ; then local namespace_config=$(${COMP_WORDS[0]} config --list | awk '/default-namespace/{print $2}') if [ ! -z $namespace_config ]; then namespace_condition=$(echo "--namespace ${namespace_config}") fi fi - + local namespace_flag=$(echo "${flaghash['-n']}${flaghash['--namespace']}") if [ ! -z $namespace_flag ]; then namespace_condition=$(echo "--namespace ${namespace_flag}") fi template="{{ range .items }}{{ .metadata.name }} {{ end }}" - template_gvkn="{{ range .items }}{{ .kind }}/{{ .apiVersion }}/{{ .metadata.name }} {{ end }}" + template_gvkn="{{ range .items }}{{ .kind }}/{{ .apiVersion }}/{{ .metadata.name }} {{ end }}" if kubectl_out=$(kubectl get -o template --template="${template}" ${namespace_condition} crd -l service.binding/provisioned-service=true 2>/dev/null); then kubectl_out="${kubectl_out// /,}" service_names="${kubectl_out}servicebinding" @@ -129,14 +129,14 @@ __kamel_kubectl_get_configmap() { local template local kubectl_out local namespace_condition - + if command -v awk &> /dev/null ; then local namespace_config=$(${COMP_WORDS[0]} config --list | awk '/default-namespace/{print $2}') if [ ! -z $namespace_config ]; then namespace_condition=$(echo "--namespace ${namespace_config}") fi fi - + local namespace_flag=$(echo "${flaghash['-n']}${flaghash['--namespace']}") if [ ! -z $namespace_flag ]; then namespace_condition=$(echo "--namespace ${namespace_flag}") @@ -153,14 +153,14 @@ __kamel_kubectl_get_secret() { local template local kubectl_out local namespace_condition - + if command -v awk &> /dev/null ; then local namespace_config=$(${COMP_WORDS[0]} config --list | awk '/default-namespace/{print $2}') if [ ! -z $namespace_config ]; then namespace_condition=$(echo "--namespace ${namespace_config}") fi fi - + local namespace_flag=$(echo "${flaghash['-n']}${flaghash['--namespace']}") if [ ! -z $namespace_flag ]; then namespace_condition=$(echo "--namespace ${namespace_flag}") @@ -177,14 +177,14 @@ __kamel_kubectl_get_integrations() { local template local kubectl_out local namespace_condition - + if command -v awk &> /dev/null ; then local namespace_config=$(${COMP_WORDS[0]} config --list | awk '/default-namespace/{print $2}') if [ ! -z $namespace_config ]; then namespace_condition=$(echo "--namespace ${namespace_config}") fi fi - + local namespace_flag=$(echo "${flaghash['-n']}${flaghash['--namespace']}") if [ ! -z $namespace_flag ]; then namespace_condition=$(echo "--namespace ${namespace_flag}") @@ -201,14 +201,14 @@ __kamel_kubectl_get_integrationkits() { local template local kubectl_out local namespace_condition - + if command -v awk &> /dev/null ; then local namespace_config=$(${COMP_WORDS[0]} config --list | awk '/default-namespace/{print $2}') if [ ! -z $namespace_config ]; then namespace_condition=$(echo "--namespace ${namespace_config}") fi fi - + local namespace_flag=$(echo "${flaghash['-n']}${flaghash['--namespace']}") if [ ! -z $namespace_flag ]; then namespace_condition=$(echo "--namespace ${namespace_flag}") @@ -225,14 +225,14 @@ __kamel_kubectl_get_non_platform_integrationkits() { local template local kubectl_out local namespace_condition - + if command -v awk &> /dev/null ; then local namespace_config=$(${COMP_WORDS[0]} config --list | awk '/default-namespace/{print $2}') if [ ! -z $namespace_config ]; then namespace_condition=$(echo "--namespace ${namespace_config}") fi fi - + local namespace_flag=$(echo "${flaghash['-n']}${flaghash['--namespace']}") if [ ! -z $namespace_flag ]; then namespace_condition=$(echo "--namespace ${namespace_flag}") @@ -250,14 +250,14 @@ __kamel_kubectl_get_kamelets() { local template local kubectl_out local namespace_condition - + if command -v awk &> /dev/null ; then local namespace_config=$(${COMP_WORDS[0]} config --list | awk '/default-namespace/{print $2}') if [ ! -z $namespace_config ]; then namespace_condition=$(echo "--namespace ${namespace_config}") fi fi - + local namespace_flag=$(echo "${flaghash['-n']}${flaghash['--namespace']}") if [ ! -z $namespace_flag ]; then namespace_condition=$(echo "--namespace ${namespace_flag}") @@ -274,14 +274,14 @@ __kamel_kubectl_get_non_bundled_non_readonly_kamelets() { local template local kubectl_out local namespace_condition - + if command -v awk &> /dev/null ; then local namespace_config=$(${COMP_WORDS[0]} config --list | awk '/default-namespace/{print $2}') if [ ! -z $namespace_config ]; then namespace_condition=$(echo "--namespace ${namespace_config}") fi fi - + local namespace_flag=$(echo "${flaghash['-n']}${flaghash['--namespace']}") if [ ! -z $namespace_flag ]; then namespace_condition=$(echo "--namespace ${namespace_flag}") @@ -430,7 +430,7 @@ func configureBashAnnotationForFlag(command *cobra.Command, flagName string, ann func computeCamelDependencies() string { catalog, err := camel.DefaultCatalog() if err != nil || catalog == nil { - catalog = camel.NewRuntimeCatalog(v1.CamelCatalog{}.Spec) + catalog = camel.NewRuntimeCatalog(v1.CamelCatalog{}) } results := make([]string, 0, len(catalog.Artifacts)+len(catalog.Loaders)) diff --git a/pkg/controller/catalog/initialize.go b/pkg/controller/catalog/initialize.go index 54961de8f8..b7194301db 100644 --- a/pkg/controller/catalog/initialize.go +++ b/pkg/controller/catalog/initialize.go @@ -31,7 +31,6 @@ import ( "github.com/apache/camel-k/pkg/client" platformutil "github.com/apache/camel-k/pkg/platform" "github.com/apache/camel-k/pkg/util" - "github.com/apache/camel-k/pkg/util/log" spectrum "github.com/container-tools/spectrum/pkg/builder" gcrv1 "github.com/google/go-containerregistry/pkg/v1" corev1 "k8s.io/api/core/v1" @@ -89,7 +88,7 @@ func initialize(options spectrum.Options, registryAddress string, catalog *v1.Ca if pipeErr != nil { // In the unlikely case of an error, use stdout instead of aborting - log.Errorf(pipeErr, "Unable to remap I/O. Spectrum messages will be displayed on the stdout") + Log.Errorf(pipeErr, "Unable to remap I/O. Spectrum messages will be displayed on the stdout") newStdW = os.Stdout } go readSpectrumLogs(newStdR) @@ -142,19 +141,19 @@ func initialize(options spectrum.Options, registryAddress string, catalog *v1.Ca } func imageExists(options spectrum.Options) bool { - log.Infof("Checking if Camel K builder container %s already exists...", options.Base) + Log.Infof("Checking if Camel K builder container %s already exists...", options.Base) ctrImg, err := spectrum.Pull(options) if ctrImg != nil && err == nil { var hash gcrv1.Hash if hash, err = ctrImg.Digest(); err != nil { - log.Errorf(err, "Cannot calculate digest") + Log.Errorf(err, "Cannot calculate digest") return false } - log.Infof("Camel K builder container with digest %s", hash.String()) + Log.Infof("found Camel K builder container with digest %s", hash.String()) return true } - log.Errorf(err, "Couldn't pull image") + Log.Errorf(err, "Couldn't pull image") return false } @@ -164,7 +163,7 @@ func buildRuntimeBuilderImage(options spectrum.Options) error { if options.Base == "" { return fmt.Errorf("Missing base image, likely catalog is not compatible with this Camel K version") } - log.Infof("Making up Camel K builder container %s", options.Target) + Log.Infof("Making up Camel K builder container %s", options.Target) if jobs := runtime.GOMAXPROCS(0); jobs > 1 { options.Jobs = jobs @@ -186,7 +185,7 @@ func readSpectrumLogs(newStdOut io.Reader) { for scanner.Scan() { line := scanner.Text() - log.Infof(line) + Log.Infof(line) } } diff --git a/pkg/controller/integrationkit/build.go b/pkg/controller/integrationkit/build.go index ed44b13dda..ad5b609633 100644 --- a/pkg/controller/integrationkit/build.go +++ b/pkg/controller/integrationkit/build.go @@ -87,30 +87,6 @@ func (action *buildAction) handleBuildSubmitted(ctx context.Context, kit *v1.Int return nil, errors.New("undefined camel catalog") } - catalog, err := kubernetes.GetCamelCatalog( - ctx, - action.client, - fmt.Sprintf("camel-catalog-%s-quarkus", env.CamelCatalog.Runtime.Version), - kit.Namespace, - ) - if err != nil { - return nil, err - } - - if catalog.Status.Phase == v1.CamelCatalogPhaseError { - kit.Status.Phase = v1.IntegrationKitPhaseError - kit.Status.SetErrorCondition( - v1.IntegrationKitConditionCatalogAvailable, - fmt.Sprintf("Camel Catalog %s error", catalog.Spec.Runtime.Version), - errors.Errorf("%s", catalog.Status.GetCondition(v1.CamelCatalogConditionReady).Reason), - ) - return kit, nil - } - if catalog.Status.Phase != v1.CamelCatalogPhaseReady { - kit.Status.Phase = v1.IntegrationKitPhaseWaitingForCatalog - return kit, nil - } - labels := kubernetes.FilterCamelCreatorLabels(kit.Labels) labels[v1.IntegrationKitLayoutLabel] = kit.Labels[v1.IntegrationKitLayoutLabel] @@ -137,6 +113,7 @@ func (action *buildAction) handleBuildSubmitted(ctx context.Context, kit *v1.Int if buildStrategy == v1.BuildStrategyPod { // We must ensure the expected service account is available or create it + // TODO make it singleton err = platform.CreateBuilderServiceAccount(env.Ctx, env.Client, env.Platform) if err != nil { return nil, errors.Wrap(err, "Error while creating Camel K Builder service account") diff --git a/pkg/controller/integrationkit/initialize.go b/pkg/controller/integrationkit/initialize.go index b0c7978045..03db0f8b1f 100644 --- a/pkg/controller/integrationkit/initialize.go +++ b/pkg/controller/integrationkit/initialize.go @@ -19,10 +19,14 @@ package integrationkit import ( "context" + "fmt" + "strings" v1 "github.com/apache/camel-k/pkg/apis/camel/v1" "github.com/apache/camel-k/pkg/trait" "github.com/apache/camel-k/pkg/util/defaults" + "github.com/apache/camel-k/pkg/util/kubernetes" + "github.com/pkg/errors" ) // NewInitializeAction creates a new initialization handling action for the kit. @@ -43,7 +47,7 @@ func (action *initializeAction) CanHandle(kit *v1.IntegrationKit) bool { } func (action *initializeAction) Handle(ctx context.Context, kit *v1.IntegrationKit) (*v1.IntegrationKit, error) { - _, err := trait.Apply(ctx, action.client, nil, kit) + env, err := trait.Apply(ctx, action.client, nil, kit) if err != nil { return nil, err } @@ -52,6 +56,33 @@ func (action *initializeAction) Handle(ctx context.Context, kit *v1.IntegrationK // by default the kit should be built kit.Status.Phase = v1.IntegrationKitPhaseBuildSubmitted } else { + + // Wait for CamelCatalog to be ready + catalog, err := kubernetes.GetCamelCatalog( + ctx, + action.client, + fmt.Sprintf("camel-catalog-%s", strings.ToLower(env.RuntimeVersion)), + kit.Namespace, + ) + if err != nil { + Log.Infof("Camel Catalog - could not retrieve catalog %s", err.Error()) + return nil, err + } + + if catalog.Status.Phase == v1.CamelCatalogPhaseError { + kit.Status.Phase = v1.IntegrationKitPhaseError + kit.Status.SetErrorCondition( + v1.IntegrationKitConditionCatalogAvailable, + fmt.Sprintf("Camel Catalog %s error", catalog.Spec.Runtime.Version), + errors.Errorf("%s", catalog.Status.GetCondition(v1.CamelCatalogConditionReady).Reason), + ) + return kit, nil + } + if catalog.Status.Phase != v1.CamelCatalogPhaseReady { + kit.Status.Phase = v1.IntegrationKitPhaseWaitingForCatalog + return kit, nil + } + // but in case it has been created from an image, mark the // kit as ready kit.Status.Phase = v1.IntegrationKitPhaseReady diff --git a/pkg/controller/integrationkit/integrationkit_controller.go b/pkg/controller/integrationkit/integrationkit_controller.go index 1c6098a476..a65cf0161d 100644 --- a/pkg/controller/integrationkit/integrationkit_controller.go +++ b/pkg/controller/integrationkit/integrationkit_controller.go @@ -260,7 +260,7 @@ func (r *reconcileIntegrationKit) Reconcile(ctx context.Context, request reconci NewErrorAction(), } - var targetPhase v1.IntegrationKitPhase + targetPhase := instance.Status.Phase for _, a := range actions { a.InjectClient(r.client) diff --git a/pkg/util/camel/camel_runtime_catalog.go b/pkg/util/camel/camel_runtime_catalog.go index 5afcaaaae6..321c78bc03 100644 --- a/pkg/util/camel/camel_runtime_catalog.go +++ b/pkg/util/camel/camel_runtime_catalog.go @@ -23,10 +23,11 @@ import ( v1 "github.com/apache/camel-k/pkg/apis/camel/v1" ) -// NewRuntimeCatalog creates a runtime catalog with the given catalog spec. -func NewRuntimeCatalog(spec v1.CamelCatalogSpec) *RuntimeCatalog { +// NewRuntimeCatalog creates a runtime catalog with the given catalog. +func NewRuntimeCatalog(cat v1.CamelCatalog) *RuntimeCatalog { catalog := RuntimeCatalog{} - catalog.CamelCatalogSpec = spec + catalog.CamelCatalogSpec = cat.Spec + catalog.CamelCatalogStatus = cat.Status catalog.artifactByScheme = make(map[string]string) catalog.artifactByDataFormat = make(map[string]string) catalog.schemesByID = make(map[string]v1.CamelScheme) diff --git a/pkg/util/camel/camel_util.go b/pkg/util/camel/camel_util.go index 4e252c9061..4dceef9afc 100644 --- a/pkg/util/camel/camel_util.go +++ b/pkg/util/camel/camel_util.go @@ -42,7 +42,7 @@ var ( func findBestMatch(catalogs []v1.CamelCatalog, runtime v1.RuntimeSpec) (*RuntimeCatalog, error) { for _, catalog := range catalogs { if catalog.Spec.Runtime.Version == runtime.Version && catalog.Spec.Runtime.Provider == runtime.Provider { - return NewRuntimeCatalog(catalog.Spec), nil + return NewRuntimeCatalog(catalog), nil } } @@ -54,7 +54,7 @@ func findBestMatch(catalogs []v1.CamelCatalog, runtime v1.RuntimeSpec) (*Runtime cc := newCatalogVersionCollection(catalogs) for _, c := range cc { if rc.Check(c.RuntimeVersion) { - return NewRuntimeCatalog(c.Catalog.Spec), nil + return NewRuntimeCatalog(*c.Catalog), nil } } diff --git a/pkg/util/camel/catalog.go b/pkg/util/camel/catalog.go index 7918fd7757..8927bd4661 100644 --- a/pkg/util/camel/catalog.go +++ b/pkg/util/camel/catalog.go @@ -156,7 +156,7 @@ func GenerateCatalogCommon( return yaml2.Unmarshal(content, &catalog) }) - return NewRuntimeCatalog(catalog.Spec), err + return NewRuntimeCatalog(catalog), err } func generateMavenProject(runtimeVersion string, providerDependencies []maven.Dependency) maven.Project {