Skip to content

Commit

Permalink
Add license headers
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro committed Sep 2, 2018
1 parent 62b4354 commit bfca1f2
Show file tree
Hide file tree
Showing 12 changed files with 232 additions and 50 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Binary files
camel-k
/camel-k

# We do not stage vendor directory
vendor
/vendor

# IDEs
.idea
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion build/get_version.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

location=$(dirname $0)
cat $location/../version/version.go | grep "Version" | awk '{print $NF}' | tr -d '"'
cat $location/../version/version.go | grep "Version" | grep "=" | awk '{print $NF}' | tr -d '"'
56 changes: 56 additions & 0 deletions cmd/camel-k/main.go
Original file line number Diff line number Diff line change
@@ -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())
}
18 changes: 18 additions & 0 deletions pkg/apis/camel/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions pkg/apis/camel/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
35 changes: 33 additions & 2 deletions pkg/apis/camel/v1alpha1/types.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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"
)
19 changes: 19 additions & 0 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
@@ -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

30 changes: 30 additions & 0 deletions pkg/stub/action/action.go
Original file line number Diff line number Diff line change
@@ -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

}
73 changes: 28 additions & 45 deletions pkg/stub/handler.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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"},
},
},
},
}
}
17 changes: 17 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down

0 comments on commit bfca1f2

Please sign in to comment.