Giter Club home page Giter Club logo

hawtio-operator's Introduction

Hawtio Operator

A Kubernetes operator, based on the Operator SDK, that operates Hawtio Online.

Upgrading

See Upgrading Guide when you are upgrading your hawtio-operator installation.

Resources

The Hawtio Custom Resource Definition (CRD) defines the Custom Resource (CR) that the operator uses to configure a Hawtio-Online operand, e.g.:

apiVersion: hawt.io/v1
kind: Hawtio
metadata:
  name: hawtio-online
spec:
  # The deployment type, either "cluster" or "namespace":
  # - cluster: Hawtio is capable of discovering and managing
  #   applications across all namespaces the authenticated user
  #   has access to.
  # - namespace: Hawtio is capable of discovering and managing
  #   applications within the deployment namespace.
  type: cluster
  # The number of desired replicas
  replicas: 1
  # The edge host name of the route that exposes the Hawtio service
  # externally. If not specified, it is automatically generated and
  # is of the form:
  #   <name>[-<namespace>].<suffix>
  # where <suffix> is the default routing sub-domain as configured for
  # the cluster.
  # Note that the operator will recreate the route if the field is emptied,
  # so that the host is re-generated.
  routeHostName: hawtio-online.hawt.io
  # The compute resources required by the deployment
  resources:
    limits:
      cpu: "1"
      memory: 200Mi
    requests:
      cpu: 200m
      memory: 32Mi

Note

The version property present in previous versions of the CRD is no longer applicable and any CRs applied to the cluster, containing this property, will have it automatically removed.

Overriding the Version of Hawtio-Online

Unlike previous versions of the operator, the version of the Hawtio-Online operand is now specified during the building of the operator. Therefore, it should be unnecessary to specify this version of the container image. However, should an override be required then it is possible to add extra environment variables to the deployment resource of this operator. Specifically:

  • IMAGE_VERSION: Adding this environment variable will override the version / tag of the Hawtio-Online container image, eg. 2.0.0-20231208;
  • IMAGE_REPOSITORY: Adding this environment variable will override the image name / repository of the Hawtio-Online container image, eg. quay.io/hawtio/online.

Features

The operator covers the following cases:

  • Creation
    • Create Deployment, ConfigMap, Service and Route resources
    • Create a service account as OAuth client in namespace deployment
    • Create an OAuth client in cluster deployment
    • Create a Secret containing a client certificate used to authenticate to Jolokia endpoints
  • Update
    • Reconcile the Deployment container image with any overriding environment variables
    • Reconcile the Route host from the routeHostName field
    • Support emptying the routeHostName field (recreate the Route to re-generate the host)
    • Reconcile the replicas field into the Deployment
    • Reconcile the resources field into the Deployment
    • Support changing deployment type from / to namespace or cluster
    • Remove previous Route host from the OAuth client in cluster deployment
    • Trigger a rollout deployment on ConfigMap changes
  • Deletion
    • Remove the Deployment, ConfigMap, Service and Route resources
    • Remove the service account as OAuth client in namespace deployment
    • Remove the route URL from the OAuth client authorized redirect URIs in cluster deployment
    • Remove the generated client certificate Secret

Custom TLS route certificate

TLS certificate for the created route is generated by default by Openshift, however it's possible to provide a own certificate stored in TLS secret and point to it in the CR: example:

oc create secret tls route-custom-cert --cert=tls.crt --key=tls.key
apiVersion: hawt.io/v1
kind: Hawtio
metadata:
  name: hawtio-online
spec:
...
  route:
    certSecret:
      name: route-custom-cert
...

Optionally it's possible to provide custom CA certificate in another secret:

oc create secret generic route-ca-cert --from-file=secretKey=tls.crt
...
route:
  certSecret:
    name: route-custom-cert
  caCert:
    name: route-ca-cert
    key: secretKey
...

If the 'key' isn't defined 'tls.crt' is automatically used.

Custom routes

To use custom routes, it is necessary to create the correct annotation in the service account. All the routes to annotate can be listed in the externalRoutes field in the custom resource:

  externalRoutes:
    - second-route
    - third-route

Deploy

To create the required resources by the operator (e.g. CRD, service account, roles, role binding, deployment, ...), run the following command:

make deploy

The above command must be executed on behalf of a privileged user, as the creation of the custom resource definition and the cluster role requires cluster-admin permission.

Note

To see the full list of available make commands and their optional environment variables, run:

make help

Test

To create and operate a Hawtio resource, you can run the following commands:

# Create Hawtio
$ kubectl apply -f deploy/crs/hawtio_v1_hawtio_cr.yaml
hawtio.hawt.io/hawtio-online created

# Get Hawtio info
$ kubectl get hawtio
NAME             AGE   URL                                           IMAGE
hawtio-online   16s   https://hawtio-online.192.168.64.38.nip.io   quay.io/hawtio/online:2.0.0

# Scale Hawtio
$ kubectl scale hawtio hawtio-online --replicas=3
hawtio.hawt.io/hawtio-online scaled

# Edit Hawtio resource
$ kubectl patch hawtio hawtio-online --type='merge' -p '{"spec":{"routeHostName":"hawtio.192.168.64.38.nip.io"}}'
hawtio.hawt.io/hawtio-online patched
# Check the status has updated accordingly
$ kubectl get hawtio
NAME             AGE   URL                                   IMAGE
hawtio-online   1m    https://hawtio.192.168.64.38.nip.io   quay.io/hawtio/online:latest

# Edit Hawtio config
$ kubectl edit configmap hawtio-online
configmap/hawtio-online edited
# Watch rollout deployment triggered by config change
$ kubectl rollout status deployment.v1.apps/hawtio-online
Waiting for deployment "hawtio-online" rollout to finish: 1 out of 3 new replicas have been updated...
Waiting for deployment "hawtio-online" rollout to finish: 2 out of 3 new replicas have been updated...
Waiting for deployment "hawtio-online" rollout to finish: 1 old replicas are pending termination...
deployment "hawtio-online" successfully rolled out

# Change the Hawtio version
$ kubectl patch hawtio hawtio-online --type='merge' -p '{"spec":{"version":"1.7.1"}}'
hawtio.hawt.io/hawtio-online patched
# Check the status has updated accordingly
$ kubectl get hawtio
NAME             AGE   URL                                   IMAGE
hawtio-online   1m    https://hawtio.192.168.64.38.nip.io   quay.io/hawtio/online:1.7.1
# Watch rollout deployment triggered by version change
$ kubectl rollout status deployment.v1.apps/hawtio-online
...
deployment "hawtio-online" successfully rolled out

# Delete Hawtio
$ kubectl delete hawtio hawtio-online
hawtio.hawt.io "hawtio-online" deleted

Develop

To build and test the operator locally, run the following command:

make build

Once you get hawtio-operator locally, you can run the operator as follows:

WATCH_NAMESPACE=<namespace> ./hawtio-operator

where WATCH_NAMESPACE is the mandatory environment variable. Setting WATCH_NAMESPACE= (empty) runs the operator as cluster type.

You can also specify the IMAGE_REPOSITORY environment variable to change the quay image repository for the hawtio-online instances from the default quay.io/hawtio/online to somewhere else. For example:

WATCH_NAMESPACE=hawtio IMAGE_REPOSITORY=quay.io/fuse/hawtio-online ./hawtio-operator

Likewise, you can specify the IMAGE_VERSION environment variable to change the version tag for the Hawtio-Online instances to a snapshot or self-compiled image. For example:

WATCH_NAMESPACE=hawtio IMAGE_REPOSITORY=quay.io/hawtio/online IMAGE_VERSION=2.0.0-202312061128 ./hawtio-operator

hawtio-operator's People

Contributors

astefanutti avatar dependabot[bot] avatar mmelko avatar myeung18 avatar phantomjinx avatar prahaladhchandrahasan avatar rashelrr avatar redhathameed avatar tadayosi avatar valdar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hawtio-operator's Issues

Console link changed by incorrect operator

The ConsoleLink objects are created with the same name of the Hawtio object. Due to not being created in the hawtio namespace, those resources are changed by multiple installations of the hawtio-operator.
The ConsoleLink objects need to include the hawtio-operator's namespace in their name to avoid conflicts.

Invalid Semantic Version caused when setting non-number value to Hawtio Version

When trying to set some non-number value (e.g. dev) to the version in Hawtio CRD, hawtio-operator fails to deploy it with the following error:

{"level":"error","ts":1605829871.2426846,"logger":"controller","msg":"Reconciler error","controller":"hawtio-controller","name":"hawtio-online","namespace":"hawtio","error":"Invalid Semantic Version","stacktrace":"github.com/go-logr/zapr.(*zapLogger).Error\n\t/go/pkg/mod/github.com/go-logr/[email protected]/zapr.go:128\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler\n\t/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:237\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\t/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:209\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).worker\n\t/go/pkg/mod/sigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:188\nk8s.io/apimachinery/pkg/util/wait.BackoffUntil.func1\n\t/go/pkg/mod/k8s.io/[email protected]/pkg/util/wait/wait.go:155\nk8s.io/apimachinery/pkg/util/wait.BackoffUntil\n\t/go/pkg/mod/k8s.io/[email protected]/pkg/util/wait/wait.go:156\nk8s.io/apimachinery/pkg/util/wait.JitterUntil\n\t/go/pkg/mod/k8s.io/[email protected]/pkg/util/wait/wait.go:133\nk8s.io/apimachinery/pkg/util/wait.Until\n\t/go/pkg/mod/k8s.io/[email protected]/pkg/util/wait/wait.go:90"}

Considering it specifies a tag for the docker image, it should accept any arbitrary values.

Support custom certificates for route

There should be a way to add custom certificates for the Route created by the operator. Alternatively there should be an option to disable the Route creation entirely, so we can add a custom Route.

Bump Go version

Currently, the Go version we use is very old. We should bump the version, if there is no problem, to the latest 1.21.0.

Update HawtioConfig type to match `@hawtio/react` hawtconfig.json model

type HawtioConfig struct {
// The information to be displayed in the About page
About HawtioAbout `json:"about,omitempty"`
// The UI branding
Branding HawtioBranding `json:"branding,omitempty"`
// The OpenShift related configuration
Online HawtioOnline `json:"online,omitempty"`
// Disables UI components with matching routes
DisabledRoutes []string `json:"disabledRoutes,omitempty"`
}

Upgrade the kubernetes api version from v1beta1 to v1

Using kubebuilder on the project displayed the following message:

⌁ [: … hawtio-operator] 1.x+* ± kubebuilder version
[Deprecation Notice] This version is deprecated and is no longer scaffolded by default since `28 Apr 2021`.The `go/v2` plugin cannot scaffold projects in which CRDs and/or Webhooks have a `v1` API version.Be aware that v1beta1 API for CRDs and Webhooks was deprecated on Kubernetes 1.16 and areremoved as of the Kubernetes 1.22 release. Therefore, since this plugin cannot produce projects thatwork on Kubernetes versions >= 1.22, it is recommended to upgrade your project to the latest versions available.

Version: main.version{KubeBuilderVersion:"3.13.0", KubernetesVendor:"1.27.1", GitCommit:"c8a7cc58eeb56586c019cf8845dad37286d077ff", BuildDate:"2023-11-02T20:43:44Z", GoOs:"linux", GoArch:"amd64"}

This highlights that the CRD API is using a deprecated version and may well stop working at some point. We should aim to upgrade the project to remove the deprecations.

Add a conversion hook to ensure CRD apis can be converted from v1alphav1 to v1

Since one version of a CRD api can be stored in the etcd, other versions are converted into this version. Without a conversion hook, the only migration that takes place is the api version number. In order to facilitate the conversion of properties then a conversion hook should be added and broadcast to the cluster.

Reference: https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definition-versioning/#before-you-begin

Support changing the image url in Hawtio CRD

There is version field that allows us to change it from latest in the Hawtio CRD, but for dev purposes sometimes it's also convenient to change the docker image url from docker.io/hawtio/online to somewhere else.

v1 `hawtio-types.go` is not synched with v1alpha1

Do

diff pkg/apis/hawtio/v1/hawtio_types.go pkg/apis/hawtio/v1alpha1/hawtio_types.go

and see what diffs there are. Please update v1 types so that it's up to date with the latest type definitions.

Operator does not respect -X setting for ImageVersion in LDFlags

When the main.ImageVersion var is assigned using a -X parameter in go's LDFlags, the tag of the hawtio-online deployment remains latest, eg.

CGO_ENABLED=0 go build -ldflags "-X main.ImageVersion=2.0.0-202311281710 -X main.ImageRepository=quay.io/phantomjinx/hawtio-online"

Restrict Secret read ClusterRole to the openshift-service-ca namespace

Following #34, the ClusterRole permission required to read the service signing certificate secret should be restricted to the openshift-service-ca namespace.

The minimal RBAC can be achieved with:

ca_role.yaml:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: hawtio-operator-ca
rules:
- apiGroups:
  - ""
  resources:
  - secrets
  resourceNames:
  - signing-key
  verbs:
  - get

ca_role_binding.yaml:

kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: hawtio-operator
  namespace: openshift-service-ca
subjects:
- kind: ServiceAccount
  name: hawtio-operator
  namespace: hawtio
roleRef:
  kind: ClusterRole
  name: hawtio-operator-ca
  apiGroup: rbac.authorization.k8s.io

That gives:

$ kubectl auth can-i get secrets/signing-key -n openshift-service-ca --as system:serviceaccount:hawtio:hawtio-operator
yes

The problem is to make is work with kustomize. We have to find a way to avoid it changes the openshift-service-ca namespace.

It seems it is possible to work-around kustomize aggresive namespace replacement, by using patches, e.g.:

deploy/kustomization.yaml:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- cluster_role_binding.yaml
- cluster_role.yaml
- ca_role.yaml
- ca_role_binding.yaml
- role.yaml
- role_binding.yaml
- service_account.yaml
- operator.yaml

patches:
- path: patch.json
  target:
    kind: Deployment
- path: patch.json
  target:
    kind: Role
- path: patch.json
  target:
    kind: ServiceAccount
- path: patch.json
  target:
    kind: RoleBinding
    namespace: ^$
- patch: |-
    - op: replace
      path: /subjects/0/namespace
      value: TEST
  target:
    kind: RoleBinding
    namespace: openshift-service-ca

deploy/patch.json:

[
  {"op": "replace", "path": "/metadata/namespace", "value": "TEST"}
]

The new problem is that OLM bundle generation with operator-sdk generate bundle does not seem to managed to take the RoleBinding into account. Actual, that seems impossible to describe such a RoleBinding (from a ClusterRole to a namespace) in the CSV resource. The way to do it seems to include the RoleBinding into the OLM bundle directory, but that has to be tested.

Document migration steps from hawtio-operator 0.3.0 to 0.4.0

There are some breaking changes since hawtio-operator 0.3.0 (#46, #48). We need to document for <=0.3.0 users the migration steps of their hawtio applications to 0.4.0. Notable changes include:

  • CRD apiVersion upgraded from apiextensions.k8s.io/v1beta to apiextensions.k8s.io/v1
  • spec.rbac.enabled field is removed from CR and types API. RBAC support is now always on and cannot be turned off.

@astefanutti I think what we really need to document is for users with the following Hawtio CR yaml (either with true or false) to just remove the field from the spec. Is my understanding correct?

spec:
    rbac:
        enabled: {true|false}

Add LICENSE file

Please can you add an appropriate LICENSE file to the top-level directory.

Consider dropping version in CR and baking it into the operator

Overview

There are a couple of recommended best practices for how operators handle the version of the operand as detailed here, namely:

  1. Operator fan-out - where the Operator allows the user to specify the version in the custom resource
  2. single version - where the Operator is tied to the version of the operand.
  3. hybrid approach - where the Operator is tied to a range of versions, and the user can select some level of the version

Currently, hawtio uses the first approach, specifying a default version in the CR yet allowing the user to change this, as appropriate. In my personal view, I think the upgrade to Hawtio-Online 2 would be a good time to switch the operator to the 2nd approach.

The 2nd approach is, to my mind, simpler in that it maintains a 1:1 relationship between operator and operand. It ensures that the upgrade process is controlled by the OLM's operator versioning pattern. As the operator is responsible for installing a number of resources, including the deployment, the current design allows the possibility that the user could install a much later operand in an old operator, resulting in a situation where all the resources in the operator no longer correctly handle features of the new operand.

The current approach only seems to specify the version number as a default. Therefore, it is possible for the user to change this to any version / tag, without any perceived limits (I cannot find any checks on the version in the operator so it may just be my ignorance :-) ).

Suggestion for Change

Remove the version from the CR and instead handle it with an environment variable and golang constant in the same manner as the image repository. This would allow the operator to be compiled with a 1:1 relationship to the operand (the golang constant) but would maintain a degree of customization by having the environment variable be available to override if necessary, eg. development / testing.

The removal of the version from the CR would be useful to remove prior to the upgrading of the CRD to 1.0.0. After that, if we chose to make this change, it would be more problematic to include such a change in a micro-version update.

Add RBAC support

As hawtio-online now provides RBAC support, it should be enabled when it's deployed with the operator.

It should be possible to provide a custom ACL file.

Install hawtio-operator with OLM

What are the recommended steps to install the operator from source with OLM? Is it already documented somewhere? If not, it's good idea to document it.

Hawtio Operator is producing 'already exist' errors for configmap in log

Errors being produced:

{"level":"error","ts":1701096292.863362,"logger":"controller_hawtio","msg":"Error reconciling ConfigMap","Request.Namespace":"hawtio-dev","Request.Name":"hawtio-online","error":"error AddResources: configmaps \"hawtio-online\" already exists","stacktrace":"github.com/hawtio/hawtio-operator/pkg/controller/hawtio.(*ReconcileHawtio).Reconcile\n\tgithub.com/hawtio/hawtio-operator/pkg/controller/hawtio/hawtio_controller.go:411\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler\n\tsigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:235\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\tsigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:209\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).worker\n\tsigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:188\nk8s.io/apimachinery/pkg/util/wait.BackoffUntil.func1\n\tk8s.io/[email protected]/pkg/util/wait/wait.go:155\nk8s.io/apimachinery/pkg/util/wait.BackoffUntil\n\tk8s.io/[email protected]/pkg/util/wait/wait.go:156\nk8s.io/apimachinery/pkg/util/wait.JitterUntil\n\tk8s.io/[email protected]/pkg/util/wait/wait.go:133\nk8s.io/apimachinery/pkg/util/wait.Until\n\tk8s.io/[email protected]/pkg/util/wait/wait.go:90"}
{"level":"error","ts":1701096292.863478,"logger":"controller","msg":"Reconciler error","controller":"hawtio-controller","name":"hawtio-online","namespace":"hawtio-dev","error":"error AddResources: configmaps \"hawtio-online\" already exists","stacktrace":"sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler\n\tsigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:237\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem\n\tsigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:209\nsigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).worker\n\tsigs.k8s.io/[email protected]/pkg/internal/controller/controller.go:188\nk8s.io/apimachinery/pkg/util/wait.BackoffUntil.func1\n\tk8s.io/[email protected]/pkg/util/wait/wait.go:155\nk8s.io/apimachinery/pkg/util/wait.BackoffUntil\n\tk8s.io/[email protected]/pkg/util/wait/wait.go:156\nk8s.io/apimachinery/pkg/util/wait.JitterUntil\n\tk8s.io/[email protected]/pkg/util/wait/wait.go:133\nk8s.io/apimachinery/pkg/util/wait.Until\n\tk8s.io/[email protected]/pkg/util/wait/wait.go:90"}

Upgrade the go version to align with internal build systems

Receiving odd golang errors with the building of the operator in build systems. Identified that the go.mod file was generated with golang 1.13 while using later version (1.19) for the golang image building the operator. Internal build systems, in turn, use golang 1.20.

So to mitigate and hopefully remove any errors, the go.mod file will be re-generated using golang 1.20, aligning with the build systems.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.