Skip to content

Commit

Permalink
Merge pull request #73 from openshift/reconciler-kubeconfig-update
Browse files Browse the repository at this point in the history
Reconciler: kubeconfig update
  • Loading branch information
openshift-merge-robot committed Oct 22, 2021
2 parents 01f4b43 + bcabd6f commit a79af53
Show file tree
Hide file tree
Showing 26 changed files with 123 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/image-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
with:
context: .
push: false
tags: dougbtv/whereabouts-ocp
tags: k8snetworkplumbingwg/whereabouts-ocp
file: Dockerfile.openshift

build-arm64:
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
FROM golang:1.13
ADD . /usr/src/whereabouts
RUN mkdir -p $GOPATH/src/github.com/dougbtv/whereabouts
WORKDIR $GOPATH/src/github.com/dougbtv/whereabouts
RUN mkdir -p $GOPATH/src/github.com/k8snetworkplumbingwg/whereabouts
WORKDIR $GOPATH/src/github.com/k8snetworkplumbingwg/whereabouts
COPY . .
RUN ./hack/build-go.sh

FROM alpine:latest
LABEL org.opencontainers.image.source https://github.com/k8snetworkplumbingwg/whereabouts
COPY --from=0 /go/src/github.com/dougbtv/whereabouts/bin/whereabouts .
COPY --from=0 /go/src/github.com/dougbtv/whereabouts/bin/ip-reconciler .
COPY --from=0 /go/src/github.com/k8snetworkplumbingwg/whereabouts/bin/whereabouts .
COPY --from=0 /go/src/github.com/k8snetworkplumbingwg/whereabouts/bin/ip-reconciler .
COPY script/install-cni.sh .
CMD ["/install-cni.sh"]
6 changes: 3 additions & 3 deletions Dockerfile.arm64
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ ADD . /usr/src/whereabouts
ENV GOARCH "arm64"
ENV GOOS "linux"

RUN mkdir -p $GOPATH/src/github.com/dougbtv/whereabouts
WORKDIR $GOPATH/src/github.com/dougbtv/whereabouts
RUN mkdir -p $GOPATH/src/github.com/k8snetworkplumbingwg/whereabouts
WORKDIR $GOPATH/src/github.com/k8snetworkplumbingwg/whereabouts
COPY . .
RUN ./hack/build-go.sh

FROM arm64v8/alpine:latest
LABEL org.opencontainers.image.source https://github.com/k8snetworkplumbingwg/whereabouts
COPY --from=0 /go/src/github.com/dougbtv/whereabouts/bin/whereabouts .
COPY --from=0 /go/src/github.com/k8snetworkplumbingwg/whereabouts/bin/whereabouts .
COPY script/install-cni.sh .
CMD ["/install-cni.sh"]
16 changes: 8 additions & 8 deletions Dockerfile.openshift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This dockerfile is used for building for OpenShift
FROM registry.ci.openshift.org/ocp/builder:rhel-8-golang-1.16-openshift-4.9 AS rhel8
ADD . /go/src/github.com/dougbtv/whereabouts
WORKDIR /go/src/github.com/dougbtv/whereabouts
ADD . /go/src/github.com/k8snetworkplumbingwg/whereabouts
WORKDIR /go/src/github.com/k8snetworkplumbingwg/whereabouts
ENV CGO_ENABLED=1
ENV GO111MODULE=on
ENV VERSION=rhel8 COMMIT=unset
Expand All @@ -10,8 +10,8 @@ RUN go build -mod vendor -o bin/ip-reconciler cmd/reconciler/*.go
WORKDIR /

FROM registry.ci.openshift.org/ocp/builder:rhel-8-golang-1.16-openshift-4.9 AS rhel7
ADD . /go/src/github.com/dougbtv/whereabouts
WORKDIR /go/src/github.com/dougbtv/whereabouts
ADD . /go/src/github.com/k8snetworkplumbingwg/whereabouts
WORKDIR /go/src/github.com/k8snetworkplumbingwg/whereabouts
ENV CGO_ENABLED=1
ENV GO111MODULE=on
RUN go build -mod vendor -o bin/whereabouts cmd/whereabouts.go
Expand All @@ -22,10 +22,10 @@ RUN mkdir -p /usr/src/whereabouts/images && \
mkdir -p /usr/src/whereabouts/bin && \
mkdir -p /usr/src/whereabouts/rhel7/bin && \
mkdir -p /usr/src/whereabouts/rhel8/bin
COPY --from=rhel7 /go/src/github.com/dougbtv/whereabouts/bin/whereabouts /usr/src/whereabouts/rhel7/bin
COPY --from=rhel8 /go/src/github.com/dougbtv/whereabouts/bin/whereabouts /usr/src/whereabouts/bin
COPY --from=rhel8 /go/src/github.com/dougbtv/whereabouts/bin/whereabouts /usr/src/whereabouts/rhel8/bin
COPY --from=rhel8 /go/src/github.com/dougbtv/whereabouts/bin/ip-reconciler /ip-reconciler
COPY --from=rhel7 /go/src/github.com/k8snetworkplumbingwg/whereabouts/bin/whereabouts /usr/src/whereabouts/rhel7/bin
COPY --from=rhel8 /go/src/github.com/k8snetworkplumbingwg/whereabouts/bin/whereabouts /usr/src/whereabouts/bin
COPY --from=rhel8 /go/src/github.com/k8snetworkplumbingwg/whereabouts/bin/whereabouts /usr/src/whereabouts/rhel8/bin
COPY --from=rhel8 /go/src/github.com/k8snetworkplumbingwg/whereabouts/bin/ip-reconciler /ip-reconciler

LABEL io.k8s.display-name="Whereabouts CNI" \
io.k8s.description="This is a component of OpenShift Container Platform and provides a cluster-wide IPAM CNI plugin." \
Expand Down
19 changes: 11 additions & 8 deletions cmd/reconciler/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,30 @@ package main
import (
"context"
"flag"
"github.com/dougbtv/whereabouts/pkg/storage"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/storage"
"os"

"github.com/dougbtv/whereabouts/pkg/logging"
"github.com/dougbtv/whereabouts/pkg/reconciler"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/logging"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/reconciler"
)

func main() {
kubeConfigFile := flag.String("kubeconfig", "", "the path to the Kubernetes configuration file")
logLevel := flag.String("log-level", "error", "the logging level for the `ip-reconciler` app. Valid values are: \"debug\", \"verbose\", \"error\", and \"panic\".")
flag.Parse()

if *kubeConfigFile == "" {
_ = logging.Errorf("must specify the kubernetes config file, via the '-kubeconfig' flag")
os.Exit(kubeconfigNotFound)
}
logging.SetLogLevel(*logLevel)

ctx, cancel := context.WithTimeout(context.Background(), storage.RequestTimeout)
defer cancel()
ipReconcileLoop, err := reconciler.NewReconcileLooper(*kubeConfigFile, ctx)

var err error
var ipReconcileLoop *reconciler.ReconcileLooper
if kubeConfigFile == nil {
ipReconcileLoop, err = reconciler.NewReconcileLooper(ctx)
} else {
ipReconcileLoop, err = reconciler.NewReconcileLooperWithKubeconfig(*kubeConfigFile, ctx)
}
if err != nil {
_ = logging.Errorf("failed to create the reconcile looper: %v", err)
os.Exit(couldNotStartOrphanedIPMonitor)
Expand Down
10 changes: 5 additions & 5 deletions cmd/reconciler/ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

"github.com/dougbtv/whereabouts/pkg/api/v1alpha1"
"github.com/dougbtv/whereabouts/pkg/reconciler"
multusv1 "github.com/k8snetworkplumbingwg/network-attachment-definition-client/pkg/apis/k8s.cni.cncf.io/v1"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/api/v1alpha1"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/reconciler"

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -66,7 +66,7 @@ var _ = Describe("Whereabouts IP reconciler", func() {
Context("reconciling the IPPool", func() {
BeforeEach(func() {
var err error
reconcileLooper, err = reconciler.NewReconcileLooper(kubeConfigPath, context.TODO())
reconcileLooper, err = reconciler.NewReconcileLooperWithKubeconfig(kubeConfigPath, context.TODO())
Expect(err).NotTo(HaveOccurred())
})

Expand Down Expand Up @@ -137,7 +137,7 @@ var _ = Describe("Whereabouts IP reconciler", func() {
Context("reconciling the IPPool", func() {
BeforeEach(func() {
var err error
reconcileLooper, err = reconciler.NewReconcileLooper(kubeConfigPath, context.TODO())
reconcileLooper, err = reconciler.NewReconcileLooperWithKubeconfig(kubeConfigPath, context.TODO())
Expect(err).NotTo(HaveOccurred())
})

Expand Down Expand Up @@ -242,7 +242,7 @@ var _ = Describe("Whereabouts IP reconciler", func() {

It("will delete an orphaned IP address", func() {
Expect(k8sClientSet.CoreV1().Pods(namespace).Delete(context.TODO(), pods[podIndexToRemove].Name, metav1.DeleteOptions{})).NotTo(HaveOccurred())
newReconciler, err := reconciler.NewReconcileLooper(kubeConfigPath, context.TODO())
newReconciler, err := reconciler.NewReconcileLooperWithKubeconfig(kubeConfigPath, context.TODO())
Expect(err).NotTo(HaveOccurred())
Expect(newReconciler.ReconcileOverlappingIPAddresses()).To(Succeed())

Expand Down
2 changes: 1 addition & 1 deletion cmd/reconciler/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

whereaboutsv1alpha1 "github.com/dougbtv/whereabouts/pkg/api/v1alpha1"
whereaboutsv1alpha1 "github.com/k8snetworkplumbingwg/whereabouts/pkg/api/v1alpha1"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
Expand Down
2 changes: 1 addition & 1 deletion cmd/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

whereaboutsv1alpha1 "github.com/dougbtv/whereabouts/pkg/api/v1alpha1"
whereaboutsv1alpha1 "github.com/k8snetworkplumbingwg/whereabouts/pkg/api/v1alpha1"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
Expand Down
14 changes: 7 additions & 7 deletions cmd/whereabouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
cnitypes "github.com/containernetworking/cni/pkg/types"
"github.com/containernetworking/cni/pkg/types/current"
cniversion "github.com/containernetworking/cni/pkg/version"
"github.com/dougbtv/whereabouts/pkg/allocate"
"github.com/dougbtv/whereabouts/pkg/config"
"github.com/dougbtv/whereabouts/pkg/logging"
"github.com/dougbtv/whereabouts/pkg/storage"
"github.com/dougbtv/whereabouts/pkg/storage/kubernetes"
"github.com/dougbtv/whereabouts/pkg/types"
"github.com/dougbtv/whereabouts/pkg/version"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/allocate"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/config"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/logging"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/storage"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/storage/kubernetes"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/types"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/version"
)

func main() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/whereabouts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/containernetworking/cni/pkg/types"
"github.com/containernetworking/cni/pkg/types/current"
"github.com/containernetworking/plugins/pkg/testutils"
"github.com/dougbtv/whereabouts/pkg/allocate"
whereaboutstypes "github.com/dougbtv/whereabouts/pkg/types"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/allocate"
whereaboutstypes "github.com/k8snetworkplumbingwg/whereabouts/pkg/types"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down
7 changes: 3 additions & 4 deletions doc/crds/ip-reconciler-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: ip-reconciler
namespace: kube-system
labels:
tier: node
app: whereabouts
Expand All @@ -11,19 +12,17 @@ spec:
spec:
template:
spec:
priorityClassName: "system-node-critical"
serviceAccountName: whereabouts
containers:
- name: whereabouts
image: ghcr.io/k8snetworkplumbingwg/whereabouts:latest-amd64
resources:
requests:
cpu: "100m"
memory: "50Mi"
limits:
cpu: "100m"
memory: "50Mi"
command:
- /ip-reconciler
- -kubeconfig=/host/etc/cni/net.d/whereabouts.d/whereabouts.kubeconfig
- -log-level=verbose
volumeMounts:
- name: cni-net-dir
Expand Down
2 changes: 1 addition & 1 deletion doc/logo-sticker.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion doc/logo.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/dougbtv/whereabouts
module github.com/k8snetworkplumbingwg/whereabouts

go 1.15

Expand Down
8 changes: 4 additions & 4 deletions hack/build-go.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ echo "VERSION: ${VERSION}"
echo "GIT_SHA: ${GIT_SHA}"
echo "GIT_TREE_STATE: ${GIT_TREE_STATE}"
echo "RELEASE_STATUS: ${RELEASE_STATUS}"
VERSION_LDFLAGS="-X github.com/dougbtv/whereabouts/pkg/version.Version=${VERSION} \
-X github.com/dougbtv/whereabouts/pkg/version.GitSHA=${GIT_SHA} \
-X github.com/dougbtv/whereabouts/pkg/version.GitTreeState=${GIT_TREE_STATE} \
-X github.com/dougbtv/whereabouts/pkg/version.ReleaseStatus=${RELEASE_STATUS}"
VERSION_LDFLAGS="-X github.com/k8snetworkplumbingwg/whereabouts/pkg/version.Version=${VERSION} \
-X github.com/k8snetworkplumbingwg/whereabouts/pkg/version.GitSHA=${GIT_SHA} \
-X github.com/k8snetworkplumbingwg/whereabouts/pkg/version.GitTreeState=${GIT_TREE_STATE} \
-X github.com/k8snetworkplumbingwg/whereabouts/pkg/version.ReleaseStatus=${RELEASE_STATUS}"
GLDFLAGS="${GLDFLAGS} ${VERSION_LDFLAGS}"

CGO_ENABLED=0 GOOS=${GOOS} GOARCH=${GOARCH} ${GO} build ${GOFLAGS} -ldflags "${GLDFLAGS}" -o bin/${cmd} cmd/${cmd}.go
Expand Down
10 changes: 6 additions & 4 deletions hack/install-kubebuilder-tools.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#!/bin/bash
OCI_BIN=${OCI_BIN:-docker}

# install controller-gen
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1

# install kubebuilder tools to bin/
mkdir -p bin
containerID=$(docker create gcr.io/kubebuilder/thirdparty-linux:1.16.4)
docker cp ${containerID}:/kubebuilder_linux_amd64.tar.gz ./kubebuilder_linux_amd64.tar.gz
docker rm ${containerID}
containerID=$("$OCI_BIN" create gcr.io/kubebuilder/thirdparty-linux:1.16.4)
"$OCI_BIN" cp ${containerID}:/kubebuilder_linux_amd64.tar.gz ./kubebuilder_linux_amd64.tar.gz
"$OCI_BIN" rm ${containerID}
tar -xzvf kubebuilder_linux_amd64.tar.gz
rm kubebuilder_linux_amd64.tar.gz
mv kubebuilder/bin/* bin/
rm -rf kubebuilder/
chmod +x bin/
chmod +x bin/

4 changes: 2 additions & 2 deletions pkg/allocate/allocate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"math"
"net"

"github.com/dougbtv/whereabouts/pkg/logging"
"github.com/dougbtv/whereabouts/pkg/types"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/logging"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/types"
)

// AssignmentError defines an IP assignment error.
Expand Down
2 changes: 1 addition & 1 deletion pkg/allocate/allocate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package allocate

import (
"fmt"
"github.com/dougbtv/whereabouts/pkg/types"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/types"
"math"
"math/big"
"net"
Expand Down
4 changes: 2 additions & 2 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

cnitypes "github.com/containernetworking/cni/pkg/types"
types020 "github.com/containernetworking/cni/pkg/types/020"
"github.com/dougbtv/whereabouts/pkg/logging"
"github.com/dougbtv/whereabouts/pkg/types"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/logging"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/types"
"github.com/imdario/mergo"
)

Expand Down
33 changes: 22 additions & 11 deletions pkg/reconciler/iploop.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"fmt"
"net"

"github.com/dougbtv/whereabouts/pkg/allocate"
whereaboutsv1alpha1 "github.com/dougbtv/whereabouts/pkg/api/v1alpha1"
"github.com/dougbtv/whereabouts/pkg/logging"
"github.com/dougbtv/whereabouts/pkg/storage"
"github.com/dougbtv/whereabouts/pkg/storage/kubernetes"
"github.com/dougbtv/whereabouts/pkg/types"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/allocate"
whereaboutsv1alpha1 "github.com/k8snetworkplumbingwg/whereabouts/pkg/api/v1alpha1"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/logging"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/storage"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/storage/kubernetes"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/types"

v1 "k8s.io/api/core/v1"
)
Expand All @@ -28,14 +28,25 @@ type OrphanedIPReservations struct {
Allocations []types.IPReservation
}

func NewReconcileLooper(kubeConfigPath string, ctx context.Context) (*ReconcileLooper, error) {
logging.Debugf("NewReconcileLooper - Kubernetes config file located at: %s", kubeConfigPath)
k8sClient, err := kubernetes.NewClient(kubeConfigPath)
func NewReconcileLooperWithKubeconfig(kubeconfigPath string, ctx context.Context) (*ReconcileLooper, error) {
logging.Debugf("NewReconcileLooper - Kubernetes config file located at: %s", kubeconfigPath)
k8sClient, err := kubernetes.NewClientViaKubeconfig(kubeconfigPath)
if err != nil {
return nil, logging.Errorf("failed to instantiate the Kubernetes client: %+v", err)
}
logging.Debugf("successfully read the kubernetes configuration file located at: %s", kubeConfigPath)
return newReconcileLooper(k8sClient, ctx)
}

func NewReconcileLooper(ctx context.Context) (*ReconcileLooper, error) {
logging.Debugf("NewReconcileLooper - inferred connection data")
k8sClient, err := kubernetes.NewClient()
if err != nil {
return nil, logging.Errorf("failed to instantiate the Kubernetes client: %+v", err)
}
return newReconcileLooper(k8sClient, ctx)
}

func newReconcileLooper(k8sClient *kubernetes.Client, ctx context.Context) (*ReconcileLooper, error) {
pods, err := k8sClient.ListPods()
if err != nil {
return nil, err
Expand Down Expand Up @@ -168,7 +179,7 @@ func (rl ReconcileLooper) ReconcileOverlappingIPAddresses() error {
failedReconciledClusterWideIPs = append(failedReconciledClusterWideIPs, overlappingIPStruct.GetName())
continue
}
logging.Debugf("removed stale overlappingIP allocation [%s]", overlappingIPStruct.GetName())
logging.Verbosef("removed stale overlappingIP allocation [%s]", overlappingIPStruct.GetName())
}

if len(failedReconciledClusterWideIPs) != 0 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciler/iploop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"

whereaboutsv1alpha1 "github.com/dougbtv/whereabouts/pkg/api/v1alpha1"
"github.com/dougbtv/whereabouts/pkg/types"
whereaboutsv1alpha1 "github.com/k8snetworkplumbingwg/whereabouts/pkg/api/v1alpha1"
"github.com/k8snetworkplumbingwg/whereabouts/pkg/types"
)

func TestIPReconciler(t *testing.T) {
Expand Down

0 comments on commit a79af53

Please sign in to comment.