Skip to content

Commit

Permalink
Fix apache#237: initial migration to operator-sdk 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro committed Jan 7, 2019
1 parent 692c4f1 commit d2fc723
Show file tree
Hide file tree
Showing 4,548 changed files with 1,482,061 additions and 27,963 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
493 changes: 308 additions & 185 deletions Gopkg.lock

Large diffs are not rendered by default.

36 changes: 17 additions & 19 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

# Force dep to vendor the code generators, which aren't imported just used at dev time.
# Picking a subpackage with Go code won't be necessary once https://github.com/golang/dep/pull/1545 is merged.
required = [
"k8s.io/code-generator/cmd/defaulter-gen",
"k8s.io/code-generator/cmd/deepcopy-gen",
Expand All @@ -14,43 +12,43 @@ required = [

[[override]]
name = "k8s.io/code-generator"
version = "kubernetes-1.11.2"
# revision for tag "kubernetes-1.12.3"
revision = "3dcf91f64f638563e5106f21f50c31fa361c918d"

[[override]]
name = "k8s.io/api"
version = "kubernetes-1.11.2"
# revision for tag "kubernetes-1.12.3"
revision = "b503174bad5991eb66f18247f52e41c3258f6348"

[[override]]
name = "k8s.io/apiextensions-apiserver"
version = "kubernetes-1.11.2"
# revision for tag "kubernetes-1.12.3"
revision = "0cd23ebeb6882bd1cdc2cb15fc7b2d72e8a86a5b"

[[override]]
name = "k8s.io/apimachinery"
version = "kubernetes-1.11.2"
# revision for tag "kubernetes-1.12.3"
revision = "eddba98df674a16931d2d4ba75edc3a389bf633a"

[[override]]
name = "k8s.io/client-go"
version = "kubernetes-1.11.2"
# revision for tag "kubernetes-1.12.3"
revision = "d082d5923d3cc0bfbb066ee5fbdea3d0ca79acf8"

[[override]]
name = "sigs.k8s.io/controller-runtime"
version = "v0.1.4"
version = "=v0.1.8"

[[constraint]]
name = "github.com/operator-framework/operator-sdk"
# The version rule is used for a specific release and the master branch for in between releases.
# branch = "master" #osdk_branch_annotation
version = "=v0.3.0" #osdk_version_annotation

[prune]
go-tests = true
non-go = true
unused-packages = true

[[prune.project]]
name = "k8s.io/code-generator"
non-go = false
unused-packages = false

[[constraint]]
name = "github.com/operator-framework/operator-sdk"
# Using fork to customize the Kubernetes rest config
source = "https://github.com/nicolaferraro/operator-sdk.git"
branch = "v0.0.7-custom"
## The version rule is used for a specific release and the master branch for in between releases.
#branch = "master"
#version = "=v0.0.7"
2 changes: 1 addition & 1 deletion Makefile
7 changes: 7 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM alpine:3.8

RUN apk upgrade --update --no-cache

USER nobody

ADD build/_output/bin/camel-k /usr/local/bin/camel-k
97 changes: 70 additions & 27 deletions cmd/camel-k/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,54 +19,97 @@ package main

import (
"context"
"flag"
"fmt"
"math/rand"
"os"
"runtime"
"time"

"github.com/apache/camel-k/pkg/stub"
"github.com/operator-framework/operator-sdk/pkg/sdk"
"github.com/operator-framework/operator-sdk/pkg/util/k8sutil"
"github.com/apache/camel-k/pkg/apis"
"github.com/apache/camel-k/pkg/controller"
"github.com/operator-framework/operator-sdk/pkg/k8sutil"
"github.com/operator-framework/operator-sdk/pkg/leader"
"github.com/operator-framework/operator-sdk/pkg/ready"
sdkVersion "github.com/operator-framework/operator-sdk/version"

_ "github.com/apache/camel-k/pkg/apis/camel/v1alpha1/knative"
_ "github.com/apache/camel-k/pkg/util/openshift"

"github.com/sirupsen/logrus"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
)

const resyncPeriod = time.Duration(5) * time.Second
var log = logf.Log.WithName("cmd")

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 watch(resource string, kind string, namespace string, resyncPeriod time.Duration) {
logrus.Infof("Watching %s, %s, %s, %d", resource, kind, namespace, resyncPeriod)
sdk.Watch(resource, kind, namespace, resyncPeriod)
log.Info(fmt.Sprintf("Go Version: %s", runtime.Version()))
log.Info(fmt.Sprintf("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH))
log.Info(fmt.Sprintf("operator-sdk Version: %v", sdkVersion.Version))
}

func main() {
rand.Seed(time.Now().UTC().UnixNano())

printVersion()
flag.Parse()

sdk.ExposeMetricsPort()
// The logger instantiated here can be changed to any logger
// implementing the logr.Logger interface. This logger will
// be propagated through the whole operator, generating
// uniform and structured logs.
logf.SetLogger(logf.ZapLogger(false))

printVersion()

resource := "camel.apache.org/v1alpha1"
namespace, err := k8sutil.GetWatchNamespace()
if err != nil {
logrus.Fatalf("failed to get watch namespace: %v", err)
log.Error(err, "failed to get watch namespace")
os.Exit(1)
}

// Get a config to talk to the apiserver
cfg, err := config.GetConfig()
if err != nil {
log.Error(err, "")
os.Exit(1)
}

// Become the leader before proceeding
leader.Become(context.TODO(), "camel-k-lock")

r := ready.NewFileReady()
err = r.Set()
if err != nil {
log.Error(err, "")
os.Exit(1)
}
defer r.Unset()

ctx := context.TODO()
// Create a new Cmd to provide shared dependencies and start components
mgr, err := manager.New(cfg, manager.Options{Namespace: namespace})
if err != nil {
log.Error(err, "")
os.Exit(1)
}

watch(resource, "Integration", namespace, resyncPeriod)
watch(resource, "IntegrationContext", namespace, resyncPeriod)
watch(resource, "IntegrationPlatform", namespace, resyncPeriod)
log.Info("Registering Components.")

sdk.Handle(stub.NewHandler(ctx, namespace))
sdk.Run(ctx)
// Setup Scheme for all resources
if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
log.Error(err, "")
os.Exit(1)
}

// Setup all Controllers
if err := controller.AddToManager(mgr); err != nil {
log.Error(err, "")
os.Exit(1)
}

log.Info("Starting the Cmd.")

// Start the Cmd
if err := mgr.Start(signals.SetupSignalHandler()); err != nil {
log.Error(err, "manager exited non-zero")
os.Exit(1)
}
}
2 changes: 0 additions & 2 deletions cmd/kamel/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import (

"github.com/apache/camel-k/pkg/client/cmd"

_ "github.com/apache/camel-k/pkg/apis/camel/v1alpha1/knative"
_ "github.com/apache/camel-k/pkg/util/openshift"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
)

Expand Down
3 changes: 0 additions & 3 deletions config/config.yaml

This file was deleted.

54 changes: 53 additions & 1 deletion deploy/resources.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions pkg/apis/addtoscheme_camel_v1alpha1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package apis

import (
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
)

func init() {
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
AddToSchemes = append(AddToSchemes, v1alpha1.SchemeBuilder.AddToScheme)
}
8 changes: 8 additions & 0 deletions pkg/apis/addtoscheme_openshift.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package apis

import "github.com/apache/camel-k/pkg/util/openshift"

func init() {
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
AddToSchemes = append(AddToSchemes, openshift.AddToScheme)
}
10 changes: 10 additions & 0 deletions pkg/apis/addtoscheme_serving_v1alpha1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package apis

import (
serving "github.com/knative/serving/pkg/apis/serving/v1alpha1"
)

func init() {
// Register the types with the Scheme so the components can map objects to GroupVersionKinds and back
AddToSchemes = append(AddToSchemes, serving.AddToScheme)
}
13 changes: 13 additions & 0 deletions pkg/apis/apis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package apis

import (
"k8s.io/apimachinery/pkg/runtime"
)

// AddToSchemes may be used to add all resources defined in the project to a Scheme
var AddToSchemes runtime.SchemeBuilder

// AddToScheme adds all Resources to the Scheme
func AddToScheme(s *runtime.Scheme) error {
return AddToSchemes.AddToScheme(s)
}
45 changes: 45 additions & 0 deletions pkg/apis/camel/v1alpha1/common_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
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

// ConfigurationSpec --
type ConfigurationSpec struct {
Type string `json:"type"`
Value string `json:"value"`
}

// Artifact --
type Artifact struct {
ID string `json:"id" yaml:"id"`
Location string `json:"location,omitempty" yaml:"location,omitempty"`
Target string `json:"target,omitempty" yaml:"target,omitempty"`
}

// Flow --
type Flow struct {
Steps []Step `json:"steps"`
}

// Flows are collections of Flow
type Flows []Flow

// Step --
type Step struct {
Kind string `json:"kind"`
URI string `json:"uri"`
}
Loading

0 comments on commit d2fc723

Please sign in to comment.