Skip to content

Commit

Permalink
Support for controller status in deploy config CR
Browse files Browse the repository at this point in the history
  • Loading branch information
vklohiya committed May 9, 2024
1 parent ceac1f6 commit 21c8ae2
Show file tree
Hide file tree
Showing 36 changed files with 1,195 additions and 339 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,5 @@ else
endif

crd-code-gen:
docker run --name crdcodegen -v $(PWD):/go/src/github.com/F5Networks/k8s-bigip-ctlr/v3 quay.io/f5networks/ciscrdcodegen:v1
docker run --platform linux/amd64 --name crdcodegen -v $(PWD):/go/src/github.com/F5Networks/k8s-bigip-ctlr/v3 quay.io/f5networks/ciscrdcodegen:v1
docker rm crdcodegen
8 changes: 4 additions & 4 deletions build-tools/crdcodegen.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ ENV GO111MODULE on
ENV PKGPATH /go/src/github.com/F5Networks/k8s-bigip-ctlr/v3

RUN mkdir -p ${GOPATH}/src/github.com/F5Networks \
&& mkdir -p ${GOPATH}/src/k8s.io \
&& go get -d k8s.io/code-generator@v0.20.4 \
&& go get -d k8s.io/apimachinery \
&& go get -d k8s.io/apiextensions-apiserver \
&& mkdir -p ${GOPATH}/src/k8s.io/ \
&& go get -d k8s.io/code-generator@v0.21.2 \
&& go get -d k8s.io/apimachinery@v0.21.2 \
&& go get -d k8s.io/apiextensions-apiserver@v0.21.2 \
&& cp -r ${GOPATH}/pkg/mod/k8s.io/api@* ${GOPATH}/src/k8s.io/api \
&& cp -r ${GOPATH}/pkg/mod/k8s.io/apiextensions-apiserver@* ${GOPATH}/src/k8s.io/apiextensions-apiserver \
&& cp -r ${GOPATH}/pkg/mod/k8s.io/apimachinery@* ${GOPATH}/src/k8s.io/apimachinery \
Expand Down
47 changes: 40 additions & 7 deletions cmd/k8s-bigip-ctlr/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/F5Networks/k8s-bigip-ctlr/v3/config/client/clientset/versioned"
"github.com/F5Networks/k8s-bigip-ctlr/v3/pkg/controller"
"github.com/F5Networks/k8s-bigip-ctlr/v3/pkg/teem"
routeclient "github.com/openshift/client-go/route/clientset/versioned/typed/route/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"net/url"
Expand Down Expand Up @@ -79,6 +81,7 @@ var (

kubeConfig *string
manageCustomResources *bool
manageRoutes *bool

cmURL *string
cmUsername *string
Expand All @@ -93,7 +96,7 @@ var (
httpAddress *string

// package variables
kubeClient kubernetes.Interface
clientSets controller.ClientSets
userAgentInfo string
multiClusterMode *string
)
Expand Down Expand Up @@ -326,7 +329,7 @@ func main() {
os.Exit(1)
}

kubeClient, err = kubernetes.NewForConfig(config)
err = initClientSets(config)
if err != nil {
log.Fatalf("[INIT] error connecting to the client: %v", err)
os.Exit(1)
Expand All @@ -343,14 +346,44 @@ func main() {
log.Infof("Exiting - signal %v\n", sig)
}

func initClientSets(config *rest.Config) error {
var err error

clientSets.KubeClient, err = kubernetes.NewForConfig(config)
if err != nil {
return fmt.Errorf("failed to create KubeClient: %v", err)
}

if *manageCustomResources {
clientSets.KubeCRClient, err = versioned.NewForConfig(config)
if err != nil {
return fmt.Errorf("failed to create Custum Resource KubeClient: %v", err)
}
}

if *manageRoutes {
clientSets.RouteClientV1, err = routeclient.NewForConfig(config)
if err != nil {
return fmt.Errorf("failed to create Route Client: %v", err)
}
}

if clientSets.KubeClient != nil {
log.Debug("Clients Created")
}
return nil

}

func initController(
config *rest.Config,
) *controller.Controller {

ctlr := controller.NewController(
ctlr := controller.RunController(
controller.Params{
Config: config,
UserAgent: userAgentInfo,
Config: config,
ClientSets: &clientSets,
UserAgent: userAgentInfo,
CMConfigDetails: &controller.CMConfig{
URL: *cmURL,
UserName: *cmUsername,
Expand Down Expand Up @@ -433,7 +466,7 @@ func getUserAgentInfo() string {
var versionInfo map[string]string
var err error
var vInfo []byte
rc := kubeClient.Discovery().RESTClient()
rc := clientSets.KubeClient.Discovery().RESTClient()
// support for ocp < 3.11
if vInfo, err = rc.Get().AbsPath(versionPathOpenshiftv3).DoRaw(context.TODO()); err == nil {
if err = json.Unmarshal(vInfo, &versionInfo); err == nil {
Expand Down Expand Up @@ -486,7 +519,7 @@ func getBIGIPTrustedCerts() string {

// getConfigMapUsingNamespaceAndName fetches and returns the configMap
func getConfigMapUsingNamespaceAndName(cfgMapNamespace, cfgMapName string) (*v1.ConfigMap, error) {
cfgMap, err := kubeClient.CoreV1().ConfigMaps(cfgMapNamespace).Get(context.TODO(), cfgMapName, metav1.GetOptions{})
cfgMap, err := clientSets.KubeClient.CoreV1().ConfigMaps(cfgMapNamespace).Get(context.TODO(), cfgMapName, metav1.GetOptions{})
if err != nil {
return nil, err
}
Expand Down
7 changes: 5 additions & 2 deletions cmd/k8s-bigip-ctlr/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"context"
"fmt"
"github.com/F5Networks/k8s-bigip-ctlr/v3/pkg/controller"
"github.com/spf13/pflag"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -258,9 +259,11 @@ var _ = Describe("Main Tests", func() {
Expect(*cmURL).To(Equal("https://cm.example.com"))
Expect(*cmUsername).To(Equal("user"))
Expect(*cmPassword).To(Equal("pass"))
kubeClient = fake.NewSimpleClientset()
clientSets = controller.ClientSets{
KubeClient: fake.NewSimpleClientset(),
}
cfgFoo := &v1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Name: "foomap", Namespace: "default"}, Data: map[string]string{"data": "foo"}}
_, err = kubeClient.CoreV1().ConfigMaps("default").Create(context.TODO(), cfgFoo, metav1.CreateOptions{})
_, err = clientSets.KubeClient.CoreV1().ConfigMaps("default").Create(context.TODO(), cfgFoo, metav1.CreateOptions{})
Expect(err).ToNot(HaveOccurred())
cfgFoo, err = getConfigMapUsingNamespaceAndName("default", "foomap")
Expect(err).ToNot(HaveOccurred())
Expand Down
87 changes: 77 additions & 10 deletions config/apis/cis/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package v1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"time"
)

// +genclient
Expand Down Expand Up @@ -211,10 +210,10 @@ type IngressLink struct {

// IngressLinkStatus is the status of the ingressLink resource.
type IngressLinkStatus struct {
VSAddress string `json:"vsAddress,omitempty"`
LastUpdated time.Time `json:"lastUpdated,omitempty"`
Error string `json:"error,omitempty"`
StatusOk string `json:"status,omitempty"`
VSAddress string `json:"vsAddress,omitempty"`
LastUpdated metav1.Time `json:"lastUpdated,omitempty"`
Error string `json:"error,omitempty"`
StatusOk string `json:"status,omitempty"`
}

// IngressLinkSpec is Spec for IngressLink
Expand Down Expand Up @@ -253,10 +252,10 @@ type TransportServer struct {

// TransportServerStatus is the status of the VirtualServer resource.
type TransportServerStatus struct {
VSAddress string `json:"vsAddress,omitempty"`
StatusOk string `json:"status,omitempty"`
LastUpdated time.Time `json:"lastUpdated,omitempty"`
Error string `json:"error,omitempty"`
VSAddress string `json:"vsAddress,omitempty"`
StatusOk string `json:"status,omitempty"`
LastUpdated metav1.Time `json:"lastUpdated,omitempty"`
Error string `json:"error,omitempty"`
}

// TransportServerSpec is the spec of the VirtualServer resource.
Expand Down Expand Up @@ -448,12 +447,15 @@ type PolicyList struct {

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:validation:Optional
// +kubebuilder:subresource:status

// DeployConfig defines the DeployConfig resource.
type DeployConfig struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec DeployConfigSpec `json:"spec"`
Spec DeployConfigSpec `json:"spec"`
Status DeployConfigStatus `json:"status,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down Expand Up @@ -590,3 +592,68 @@ type ClusterDetails struct {
Ratio *int `json:"ratio"`
AdminState AdminState `json:"adminState"`
}

type ControllerStatus struct {
Type string `json:"type"`
Message string `json:"message"`
Error string `json:"error,omitempty"`
LastUpdated metav1.Time `json:"lastUpdated,omitempty"`
}

type BigIPStatus struct {
BigIPAddress string `json:"bigIpAddress"`
L3Status L3Status `json:"l3Status,omitempty"`
AS3Status AS3Status `json:"as3Status,omitempty"`
}

type K8SClusterStatus struct {
ClusterName string `json:"clusterName"`
Message string `json:"message"`
Error string `json:"error,omitempty"`
LastUpdated metav1.Time `json:"lastUpdated,omitempty"`
}

type HAStatus struct {
PrimaryEndPoint string `json:"primaryEndPoint"`
PrimaryEndPointStatus string `json:"primaryEndPointStatus"`
LastSuccess metav1.Time `json:"lastSuccess,omitempty"`
LastFailure metav1.Time `json:"lastFailure,omitempty"`
Error string `json:"error,omitempty"`
ProbesSuccessSinceClkRst int32 `json:"probesSuccessSinceClkRst"`
ProbesFailSinceClkRst int32 `json:"probesFailSinceClkRst"`
}

type DeployConfigStatus struct {
ControllerStatus ControllerStatus `json:"controllerStatus,omitempty"`
CMStatus CMStatus `json:"cmStatus,omitempty"`
NetworkConfigStatus NetworkConfigStatus `json:"networkConfigStatus,omitempty"`
BigIPStatus []BigIPStatus `json:"bigIpStatus,omitempty"`
K8SClusterStatus []K8SClusterStatus `json:"k8sClusterStatus,omitempty"`
HAStatus []HAStatus `json:"haStatus,omitempty"`
}

type CMStatus struct {
Message string `json:"message"`
Error string `json:"error,omitempty"`
LastUpdated metav1.Time `json:"lastUpdated,omitempty"`
}

type NetworkConfigStatus struct {
Message string `json:"message"`
Error string `json:"error,omitempty"`
LastUpdated metav1.Time `json:"lastUpdated,omitempty"`
}

type AS3Status struct {
Message string `json:"message"`
Error string `json:"error,omitempty"`
LastSubmitted metav1.Time `json:"lastSubmitted,omitempty"`
LastSuccessful metav1.Time `json:"lastSuccessful,omitempty"`
}

type L3Status struct {
Message string `json:"message"`
Error string `json:"error,omitempty"`
LastSubmitted metav1.Time `json:"lastSubmitted,omitempty"`
LastSuccessful metav1.Time `json:"lastSuccessful,omitempty"`
}
Loading

0 comments on commit 21c8ae2

Please sign in to comment.