You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2018/09/06 11:06:30 UTC

[camel-k] 02/05: Add license headers

This is an automated email from the ASF dual-hosted git repository.

nferraro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k.git

commit bfca1f2d2e87b18c69c8c3f76cb6f81ebacbaec7
Author: nferraro <ni...@gmail.com>
AuthorDate: Sun Sep 2 08:35:59 2018 +0200

    Add license headers
---
 .gitignore                          |  4 +-
 LICENSE.txt => LICENSE              |  0
 NOTICE                              | 11 ++++++
 build/get_version.sh                |  2 +-
 cmd/camel-k/main.go                 | 56 ++++++++++++++++++++++++++++
 pkg/apis/camel/v1alpha1/doc.go      | 18 +++++++++
 pkg/apis/camel/v1alpha1/register.go | 17 +++++++++
 pkg/apis/camel/v1alpha1/types.go    | 35 +++++++++++++++++-
 pkg/build/build.go                  | 19 ++++++++++
 pkg/stub/action/action.go           | 30 +++++++++++++++
 pkg/stub/handler.go                 | 73 ++++++++++++++-----------------------
 version/version.go                  | 17 +++++++++
 12 files changed, 232 insertions(+), 50 deletions(-)

diff --git a/.gitignore b/.gitignore
index 5819a19..319e113 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,8 +1,8 @@
 # Binary files
-camel-k
+/camel-k
 
 # We do not stage vendor directory
-vendor
+/vendor
 
 # IDEs
 .idea
diff --git a/LICENSE.txt b/LICENSE
similarity index 100%
rename from LICENSE.txt
rename to LICENSE
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..f4f1281
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,11 @@
+   =========================================================================
+   ==  NOTICE file corresponding to the section 4 d of                    ==
+   ==  the Apache License, Version 2.0,                                   ==
+   ==  in this case for the Apache Camel distribution.                    ==
+   =========================================================================
+
+   This product includes software developed by
+   The Apache Software Foundation (http://www.apache.org/).
+
+   Please read the different LICENSE files present in the licenses directory of
+   this distribution.
\ No newline at end of file
diff --git a/build/get_version.sh b/build/get_version.sh
index 0b78013..1357527 100755
--- a/build/get_version.sh
+++ b/build/get_version.sh
@@ -1,4 +1,4 @@
 #!/bin/sh
 
 location=$(dirname $0)
-cat $location/../version/version.go | grep "Version" | awk '{print $NF}' | tr -d '"'
\ No newline at end of file
+cat $location/../version/version.go | grep "Version" | grep "=" | awk '{print $NF}' | tr -d '"'
\ No newline at end of file
diff --git a/cmd/camel-k/main.go b/cmd/camel-k/main.go
new file mode 100644
index 0000000..63c4fc0
--- /dev/null
+++ b/cmd/camel-k/main.go
@@ -0,0 +1,56 @@
+/*
+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 main
+
+import (
+	"context"
+	"runtime"
+	"time"
+
+	stub "github.com/apache/camel-k/pkg/stub"
+	sdk "github.com/operator-framework/operator-sdk/pkg/sdk"
+	k8sutil "github.com/operator-framework/operator-sdk/pkg/util/k8sutil"
+	sdkVersion "github.com/operator-framework/operator-sdk/version"
+
+	"github.com/sirupsen/logrus"
+	_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
+)
+
+func printVersion() {
+	logrus.Infof("Go Version: %s", runtime.Version())
+	logrus.Infof("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH)
+	logrus.Infof("operator-sdk Version: %v", sdkVersion.Version)
+}
+
+func main() {
+	printVersion()
+
+	sdk.ExposeMetricsPort()
+
+	resource := "camel.apache.org/v1alpha1"
+	kind := "Integration"
+	namespace, err := k8sutil.GetWatchNamespace()
+	if err != nil {
+		logrus.Fatalf("failed to get watch namespace: %v", err)
+	}
+	resyncPeriod := time.Duration(5) * time.Second
+	logrus.Infof("Watching %s, %s, %s, %d", resource, kind, namespace, resyncPeriod)
+	sdk.Watch(resource, kind, namespace, resyncPeriod)
+	sdk.Handle(stub.NewHandler())
+	sdk.Run(context.TODO())
+}
diff --git a/pkg/apis/camel/v1alpha1/doc.go b/pkg/apis/camel/v1alpha1/doc.go
index 0745fff..c937536 100644
--- a/pkg/apis/camel/v1alpha1/doc.go
+++ b/pkg/apis/camel/v1alpha1/doc.go
@@ -1,3 +1,21 @@
 // +k8s:deepcopy-gen=package
 // +groupName=camel.apache.org
+
+/*
+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 v1alpha1
diff --git a/pkg/apis/camel/v1alpha1/register.go b/pkg/apis/camel/v1alpha1/register.go
index a054677..dbbdfd7 100644
--- a/pkg/apis/camel/v1alpha1/register.go
+++ b/pkg/apis/camel/v1alpha1/register.go
@@ -1,3 +1,20 @@
+/*
+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 v1alpha1
 
 import (
diff --git a/pkg/apis/camel/v1alpha1/types.go b/pkg/apis/camel/v1alpha1/types.go
index 158e8c0..d1a4431 100644
--- a/pkg/apis/camel/v1alpha1/types.go
+++ b/pkg/apis/camel/v1alpha1/types.go
@@ -1,3 +1,20 @@
+/*
+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 v1alpha1
 
 import (
@@ -22,8 +39,22 @@ type Integration struct {
 }
 
 type IntegrationSpec struct {
-	// Fill me
+	Replicas   *int32       `json:"replicas,omitempty"`
+	Source     SourceSpec   `json:"source,omitempty"`
+}
+
+type SourceSpec struct {
+    Code    *string `json:"code,omitempty"`
 }
+
 type IntegrationStatus struct {
-	// Fill me
+	Phase   IntegrationPhase    `json:"phase,omitempty"`
 }
+
+type IntegrationPhase string
+
+const (
+    IntegrationPhaseBuilding    IntegrationPhase = "Building"
+    IntegrationPhaseRunning     IntegrationPhase = "Running"
+    IntegrationPhaseError       IntegrationPhase = "Error"
+)
\ No newline at end of file
diff --git a/pkg/build/build.go b/pkg/build/build.go
new file mode 100644
index 0000000..88d762c
--- /dev/null
+++ b/pkg/build/build.go
@@ -0,0 +1,19 @@
+/*
+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 build
+
diff --git a/pkg/stub/action/action.go b/pkg/stub/action/action.go
new file mode 100644
index 0000000..185105f
--- /dev/null
+++ b/pkg/stub/action/action.go
@@ -0,0 +1,30 @@
+/*
+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 action
+
+import (
+	"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
+)
+
+type Action interface {
+
+	CanExecute(integration *v1alpha1.Integration) bool
+
+	Execute(syndesis *v1alpha1.Integration) error
+
+}
diff --git a/pkg/stub/handler.go b/pkg/stub/handler.go
index 749d304..8f6fd16 100644
--- a/pkg/stub/handler.go
+++ b/pkg/stub/handler.go
@@ -1,3 +1,20 @@
+/*
+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 stub
 
 import (
@@ -6,63 +23,29 @@ import (
 	"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
 
 	"github.com/operator-framework/operator-sdk/pkg/sdk"
-	"github.com/sirupsen/logrus"
-	corev1 "k8s.io/api/core/v1"
-	"k8s.io/apimachinery/pkg/api/errors"
-	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
-	"k8s.io/apimachinery/pkg/runtime/schema"
+	"github.com/apache/camel-k/pkg/stub/action"
 )
 
 func NewHandler() sdk.Handler {
-	return &Handler{}
+	return &Handler{
+		actionPool: []action.Action{},
+	}
 }
 
 type Handler struct {
-	// Fill me
+	actionPool	[]action.Action
 }
 
 func (h *Handler) Handle(ctx context.Context, event sdk.Event) error {
 	switch o := event.Object.(type) {
 	case *v1alpha1.Integration:
-		err := sdk.Create(newbusyBoxPod(o))
-		if err != nil && !errors.IsAlreadyExists(err) {
-			logrus.Errorf("failed to create busybox pod : %v", err)
-			return err
+		for _, a := range h.actionPool {
+			if a.CanExecute(o) {
+				if err := a.Execute(o); err != nil {
+					return err
+				}
+			}
 		}
 	}
 	return nil
 }
-
-// newbusyBoxPod demonstrates how to create a busybox pod
-func newbusyBoxPod(cr *v1alpha1.Integration) *corev1.Pod {
-	labels := map[string]string{
-		"app": "busy-box",
-	}
-	return &corev1.Pod{
-		TypeMeta: metav1.TypeMeta{
-			Kind:       "Pod",
-			APIVersion: "v1",
-		},
-		ObjectMeta: metav1.ObjectMeta{
-			Name:      "busy-box",
-			Namespace: cr.Namespace,
-			OwnerReferences: []metav1.OwnerReference{
-				*metav1.NewControllerRef(cr, schema.GroupVersionKind{
-					Group:   v1alpha1.SchemeGroupVersion.Group,
-					Version: v1alpha1.SchemeGroupVersion.Version,
-					Kind:    "Integration",
-				}),
-			},
-			Labels: labels,
-		},
-		Spec: corev1.PodSpec{
-			Containers: []corev1.Container{
-				{
-					Name:    "busybox",
-					Image:   "busybox",
-					Command: []string{"sleep", "3600"},
-				},
-			},
-		},
-	}
-}
diff --git a/version/version.go b/version/version.go
index 74ac223..6d8b94b 100644
--- a/version/version.go
+++ b/version/version.go
@@ -1,3 +1,20 @@
+/*
+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 version
 
 var (