Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some Knative improvements #336

Merged
merged 4 commits into from
Jan 18, 2019
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
19 changes: 10 additions & 9 deletions pkg/apis/camel/v1alpha1/integration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import (

// IntegrationSpec defines the desired state of Integration
type IntegrationSpec struct {
Replicas *int32 `json:"replicas,omitempty"`
Sources []SourceSpec `json:"sources,omitempty"`
Resources []ResourceSpec `json:"resources,omitempty"`
Context string `json:"context,omitempty"`
Dependencies []string `json:"dependencies,omitempty"`
Profile TraitProfile `json:"profile,omitempty"`
Traits map[string]IntegrationTraitSpec `json:"traits,omitempty"`
Configuration []ConfigurationSpec `json:"configuration,omitempty"`
Repositories []string `json:"repositories,omitempty"`
Replicas *int32 `json:"replicas,omitempty"`
Sources []SourceSpec `json:"sources,omitempty"`
Resources []ResourceSpec `json:"resources,omitempty"`
Context string `json:"context,omitempty"`
Dependencies []string `json:"dependencies,omitempty"`
Profile TraitProfile `json:"profile,omitempty"`
Traits map[string]IntegrationTraitSpec `json:"traits,omitempty"`
Configuration []ConfigurationSpec `json:"configuration,omitempty"`
Repositories []string `json:"repositories,omitempty"`
ServiceAccountName string `json:"serviceAccountName,omitempty"`
}

// IntegrationStatus defines the observed state of Integration
Expand Down
3 changes: 1 addition & 2 deletions pkg/controller/integrationplatform/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package integrationplatform

import (
"context"
"errors"

"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
platformutils "github.com/apache/camel-k/pkg/platform"
Expand Down Expand Up @@ -85,7 +84,7 @@ func (action *initializeAction) Handle(ctx context.Context, platform *v1alpha1.I
}

if target.Spec.Build.PublishStrategy == v1alpha1.IntegrationPlatformBuildPublishStrategyKaniko && target.Spec.Build.Registry == "" {
return errors.New("no registry specified for publishing images")
logrus.Warning("No registry specified for publishing images")
}

if target.Spec.Profile == "" {
Expand Down
3 changes: 2 additions & 1 deletion pkg/gzip/compress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ limitations under the License.
package gzip

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestCompression(t *testing.T) {
Expand Down
24 changes: 24 additions & 0 deletions pkg/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ import (
"sort"

"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"github.com/apache/camel-k/pkg/gzip"
src "github.com/apache/camel-k/pkg/util/source"
"github.com/sirupsen/logrus"
)

// ExtractAll returns metadata information from all listed source codes
Expand Down Expand Up @@ -68,6 +70,12 @@ func merge(m1 IntegrationMetadata, m2 IntegrationMetadata) IntegrationMetadata {

// Extract returns metadata information from the source code
func Extract(source v1alpha1.SourceSpec) IntegrationMetadata {
var err error
source, err = uncompress(source)
if err != nil {
logrus.Errorf("unable to uncompress source %s: %v", source.Name, err)
}

language := source.InferLanguage()

m := IntegrationMetadata{}
Expand All @@ -91,3 +99,19 @@ func Each(sources []v1alpha1.SourceSpec, consumer func(int, IntegrationMetadata)
}
}
}

func uncompress(spec v1alpha1.SourceSpec) (v1alpha1.SourceSpec, error) {
if spec.Compression {
data := []byte(spec.Content)
var uncompressed []byte
var err error
if uncompressed, err = gzip.UncompressBase64(data); err != nil {
return spec, err
}
newSpec := spec
newSpec.Compression = false
newSpec.Content = string(uncompressed)
return newSpec, nil
}
return spec, nil
}
68 changes: 36 additions & 32 deletions pkg/trait/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,43 @@ import (

// Catalog collects all information about traits in one place
type Catalog struct {
tDebug Trait
tDependencies Trait
tDeployment Trait
tKnative Trait
tService Trait
tRoute Trait
tIngress Trait
tOwner Trait
tImages Trait
tBuilder Trait
tSpringBoot Trait
tIstio Trait
tEnvironment Trait
tClasspath Trait
tRest Trait
tDebug Trait
tDependencies Trait
tDeployment Trait
tKnativeService Trait
tKnative Trait
tService Trait
tRoute Trait
tIngress Trait
tOwner Trait
tImages Trait
tBuilder Trait
tSpringBoot Trait
tIstio Trait
tEnvironment Trait
tClasspath Trait
tRest Trait
}

// NewCatalog creates a new trait Catalog
func NewCatalog(ctx context.Context, c client.Client) *Catalog {
catalog := Catalog{
tDebug: newDebugTrait(),
tRest: newRestTrait(),
tDependencies: newDependenciesTrait(),
tDeployment: newDeploymentTrait(),
tKnative: newKnativeTrait(),
tService: newServiceTrait(),
tRoute: newRouteTrait(),
tIngress: newIngressTrait(),
tOwner: newOwnerTrait(),
tImages: newImagesTrait(),
tBuilder: newBuilderTrait(),
tSpringBoot: newSpringBootTrait(),
tIstio: newIstioTrait(),
tEnvironment: newEnvironmentTrait(),
tClasspath: newClasspathTrait(),
tDebug: newDebugTrait(),
tRest: newRestTrait(),
tKnative: newKnativeTrait(),
tDependencies: newDependenciesTrait(),
tDeployment: newDeploymentTrait(),
tKnativeService: newKnativeServiceTrait(),
tService: newServiceTrait(),
tRoute: newRouteTrait(),
tIngress: newIngressTrait(),
tOwner: newOwnerTrait(),
tImages: newImagesTrait(),
tBuilder: newBuilderTrait(),
tSpringBoot: newSpringBootTrait(),
tIstio: newIstioTrait(),
tEnvironment: newEnvironmentTrait(),
tClasspath: newClasspathTrait(),
}

for _, t := range catalog.allTraits() {
Expand All @@ -82,9 +84,10 @@ func (c *Catalog) allTraits() []Trait {
return []Trait{
c.tDebug,
c.tRest,
c.tKnative,
c.tDependencies,
c.tDeployment,
c.tKnative,
c.tKnativeService,
c.tService,
c.tRoute,
c.tIngress,
Expand Down Expand Up @@ -134,14 +137,15 @@ func (c *Catalog) traitsFor(environment *Environment) []Trait {
return []Trait{
c.tDebug,
c.tRest,
c.tKnative,
c.tDependencies,
c.tImages,
c.tBuilder,
c.tEnvironment,
c.tClasspath,
c.tSpringBoot,
c.tKnative,
c.tDeployment,
c.tKnativeService,
c.tIstio,
c.tOwner,
}
Expand Down
10 changes: 8 additions & 2 deletions pkg/trait/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@ func (t *deploymentTrait) Configure(e *Environment) (bool, error) {

if e.IntegrationInPhase(v1alpha1.IntegrationPhaseDeploying) {
//
// Don't deploy on knative
// Don't deploy when a different strategy is needed (e.g. Knative)
//
return e.DetermineProfile() != v1alpha1.TraitProfileKnative, nil
var strategy ControllerStrategy
var err error
if strategy, err = e.DetermineControllerStrategy(t.ctx, t.client); err != nil {
return false, err
}
return strategy == ControllerStrategyDeployment, nil
}

if t.ContainerImage && e.InPhase(v1alpha1.IntegrationContextPhaseReady, v1alpha1.IntegrationPhaseBuildingContext) {
Expand Down Expand Up @@ -290,6 +295,7 @@ func (t *deploymentTrait) getDeploymentFor(e *Environment) *appsv1.Deployment {
Labels: labels,
},
Spec: corev1.PodSpec{
ServiceAccountName: e.Integration.Spec.ServiceAccountName,
Containers: []corev1.Container{
{
Name: e.Integration.Name,
Expand Down
14 changes: 9 additions & 5 deletions pkg/trait/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ type istioTrait struct {
}

const (
istioIncludeAnnotation = "traffic.sidecar.istio.io/includeOutboundIPRanges"
istioSidecarInjectAnnotation = "sidecar.istio.io/inject"
istioOutboundIPRangesAnnotation = "traffic.sidecar.istio.io/includeOutboundIPRanges"
)

func newIstioTrait() *istioTrait {
Expand All @@ -52,19 +53,22 @@ func (t *istioTrait) Configure(e *Environment) (bool, error) {
func (t *istioTrait) Apply(e *Environment) error {
if t.Allow != "" {
e.Resources.VisitDeployment(func(d *appsv1.Deployment) {
d.Spec.Template.Annotations = t.injectIstioAnnotation(d.Spec.Template.Annotations)
d.Spec.Template.Annotations = t.injectIstioAnnotation(d.Spec.Template.Annotations, true)
})
e.Resources.VisitKnativeConfigurationSpec(func(cs *serving.ConfigurationSpec) {
cs.RevisionTemplate.Annotations = t.injectIstioAnnotation(cs.RevisionTemplate.Annotations)
cs.RevisionTemplate.Annotations = t.injectIstioAnnotation(cs.RevisionTemplate.Annotations, false)
})
}
return nil
}

func (t *istioTrait) injectIstioAnnotation(annotations map[string]string) map[string]string {
func (t *istioTrait) injectIstioAnnotation(annotations map[string]string, includeInject bool) map[string]string {
if annotations == nil {
annotations = make(map[string]string)
}
annotations[istioIncludeAnnotation] = t.Allow
annotations[istioOutboundIPRangesAnnotation] = t.Allow
if includeInject {
annotations[istioSidecarInjectAnnotation] = "true"
}
return annotations
}
Loading