Skip to content

Commit

Permalink
ACI CNI Operator for OpenShift4.X/K8s Platform
Browse files Browse the repository at this point in the history
  • Loading branch information
abhis2112 committed Jan 31, 2020
1 parent 4c0e92a commit 62987ea
Show file tree
Hide file tree
Showing 32 changed files with 2,146 additions and 2 deletions.
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ VENDOR_BUILD_CMD ?= dep ensure -v

all: vendor dist/aci-containers-host-agent dist/opflex-agent-cni \
dist/aci-containers-controller dist/acikubectl dist/ovsresync \
dist/gbpserver
dist/gbpserver \
dist/aci-containers-operator
all-static: vendor dist-static/aci-containers-host-agent \
dist-static/opflex-agent-cni dist-static/aci-containers-controller \
dist-static/ovsresync dist-static/gbpserver
dist-static/ovsresync dist-static/gbpserver \
dist-static/aci-containers-operator

go-targets: nodep-opflex-agent-cni nodep-aci-containers-host-agent nodep-aci-containers-controller gbpserver
go-build:
Expand Down Expand Up @@ -155,6 +157,11 @@ dist/acikubectl: ${ACIKUBECTL_DEPS}
dist-static/acikubectl: ${ACIKUBECTL_DEPS}
${STATIC_BUILD_CMD} -o $@ ${BASE}/cmd/acikubectl

dist/aci-containers-operator:
${BUILD_CMD} -o $@ ${BASE}/cmd/acicontainersoperator
dist-static/aci-containers-operator:
${STATIC_BUILD_CMD} -o $@ ${BASE}/cmd/acicontainersoperator

dist/ovsresync: ${OVSRESYNC_DEPS}
${BUILD_CMD} -o $@ ${BASE}/cmd/ovsresync
dist-static/ovsresync: ${OVSRESYNC_DEPS}
Expand All @@ -179,6 +186,8 @@ container-cnideploy:
${DOCKER_BUILD_CMD} -t ${DOCKER_HUB_ID}/cnideploy${DOCKER_TAG} -f ./docker/Dockerfile-cnideploy docker
container-simpleservice: dist-static/simpleservice
${DOCKER_BUILD_CMD} -t ${DOCKER_HUB_ID}/simpleservice${DOCKER_TAG} -f ./docker/Dockerfile-simpleservice .
container-operator: dist-static/aci-containers-operator
${DOCKER_BUILD_CMD} -t noiro/aci-containers-operator -f ./docker/Dockerfile-operator .

check: check-ipam check-index check-apicapi check-controller check-hostagent check-keyvalueservice check-gbpserver
check-ipam:
Expand Down
64 changes: 64 additions & 0 deletions cmd/acicontainersoperator/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright 2020 Cisco Systems, Inc.
//
// Licensed 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 (
log "github.com/Sirupsen/logrus"
operatorclientset "github.com/noironetworks/aci-containers/pkg/acicontainersoperator/clientset/versioned"
"github.com/noironetworks/aci-containers/pkg/controller"
restclient "k8s.io/client-go/rest"
"os"
"os/signal"
"syscall"
)

// Create K8s Client
func getOperatorClient() operatorclientset.Interface {

restconfig, err := restclient.InClusterConfig()
if err != nil {
return nil
}

kubeClient, err := operatorclientset.NewForConfig(restconfig)
if err != nil {
log.Fatalf("Failed to intialize kube client %v", err)
}

log.Info("Successfully constructed k8s client")
return kubeClient
}


func main() {
// get the Kubernetes client for connectivity
log.Debug("Initializing kubernetes client")
client := getOperatorClient()
if client == nil{
log.Fatalf("Failed to intialize kube client", )
return
}

cont := controller.NewAciContainersOperator(client)

stopCh := make(chan struct{})
defer close(stopCh)
go cont.Run(stopCh)

sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGTERM)
signal.Notify(sig, syscall.SIGINT)
<-sig
}
12 changes: 12 additions & 0 deletions crd-code-generation/hack/update-codegen-containersoperator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail

SCRIPT_ROOT=$(dirname ${PWD})

vendor/k8s.io/code-generator/generate-groups.sh all \
github.com/noironetworks/aci-containers/pkg/acicontainersoperator github.com/noironetworks/aci-containers/pkg/acicontainersoperator/apis \
aci.ctrl:v1alpha1 \
--go-header-file ${SCRIPT_ROOT}/aci-containers/crd-code-generation/hack/custom-boilerplate.go.txt
7 changes: 7 additions & 0 deletions docker/Dockerfile-operator
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM alpine:3.10.2
RUN apk upgrade --no-cache
RUN apk update && apk add curl git
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.14.6/bin/linux/amd64/kubectl
RUN chmod u+x kubectl && mv kubectl /usr/local/bin/kubectl
COPY dist-static/aci-containers-operator /usr/local/bin/
ENTRYPOINT ["/usr/local/bin/aci-containers-operator"]
5 changes: 5 additions & 0 deletions pkg/acicontainersoperator/apis/aci.ctrl/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package acictrl

const (
GroupName = "aci.ctrl"
)
5 changes: 5 additions & 0 deletions pkg/acicontainersoperator/apis/aci.ctrl/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// +k8s:deepcopy-gen=package,register

// Package v1 is the v1 version of the API.
// +groupName=aci.ctrl
package v1alpha1
40 changes: 40 additions & 0 deletions pkg/acicontainersoperator/apis/aci.ctrl/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"

operator "github.com/noironetworks/aci-containers/pkg/acicontainersoperator/apis/aci.ctrl"
)

// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: operator.GroupName, Version: "v1alpha1"}

// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}

var (
// localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes.
SchemeBuilder runtime.SchemeBuilder
localSchemeBuilder = &SchemeBuilder
AddToScheme = localSchemeBuilder.AddToScheme
)

func init() {
// We only register manually written functions here. The registration of the
// generated functions takes place in the generated files. The separation
// makes the code compile even when the generated files are missing.
localSchemeBuilder.Register(addKnownTypes)
}

// Adds the list of known types to api.Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&AciContainersOperator{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}
45 changes: 45 additions & 0 deletions pkg/acicontainersoperator/apis/aci.ctrl/v1alpha1/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)


// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// AciContainersOperator is a specification for a AciContainersOperator resource
type AciContainersOperator struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec AciContainersOperatorSpec `json:"spec,omitempty"`
Status AciContainersOperatorStatus `json:"status,omitempty"`
}

// AciContainersOperatorSpec defines the desired state of AciContainersOperator
type AciContainersOperatorSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "acioperator-sdk generate k8s" to regenerate code after modifying this file
// Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html
Flavor string `json:"flavor"`
Config string `json:"config"`
}

// AciContainersOperatorStatus defines the observed state of AciContainersOperator
type AciContainersOperatorStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "acioperator-sdk generate k8s" to regenerate code after modifying this file
// Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html
Status bool `json:"Successful or Not"`
}


// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// AciContainersOperator list
type AciContainersOperatorList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []AciContainersOperator `json:"items"`
}

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

Loading

0 comments on commit 62987ea

Please sign in to comment.