[GitHub] lburgazzoli commented on a change in pull request #261: Better Knative and Istio integration

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[GitHub] lburgazzoli commented on a change in pull request #261: Better Knative and Istio integration

GitBox
lburgazzoli commented on a change in pull request #261: Better Knative and Istio integration
URL: https://github.com/apache/camel-k/pull/261#discussion_r239365785
 
 

 ##########
 File path: pkg/trait/istio.go
 ##########
 @@ -0,0 +1,64 @@
+/*
+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 trait
+
+import (
+ "github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+ serving "github.com/knative/serving/pkg/apis/serving/v1alpha1"
+ appsv1 "k8s.io/api/apps/v1"
+)
+
+type istioTrait struct {
+ BaseTrait `property:",squash"`
+ Allow     string `property:"allow"`
+}
+
+const (
+ istioIncludeAnnotation = "traffic.sidecar.istio.io/includeOutboundIPRanges"
+)
+
+func newIstioTrait() *istioTrait {
+ return &istioTrait{
+ BaseTrait: newBaseTrait("istio"),
+ Allow:     "10.0.0.0/8,172.16.0.0/12,192.168.0.0/16",
+ }
+}
+
+func (t *istioTrait) appliesTo(e *Environment) bool {
+ return e.Integration != nil && e.Integration.Status.Phase == v1alpha1.IntegrationPhaseDeploying
+}
+
+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)
+ })
+ e.Resources.VisitKnativeConfigurationSpec(func(cs *serving.ConfigurationSpec) {
+ cs.RevisionTemplate.Annotations = t.injectIstioAnnotation(cs.RevisionTemplate.Annotations)
+ })
+ }
+ return nil
+}
+
+func (t *istioTrait) injectIstioAnnotation(annotations map[string]string) map[string]string {
+ if annotations == nil {
+ annotations = make(map[string]string)
+ }
+ annotations[istioIncludeAnnotation] = t.Allow
 
 Review comment:
   for future development: we also need a generic way to provide annotations/labels from integration/context

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


With regards,
Apache Git Services