Skip to content

Commit

Permalink
feat: Removes the hawtio-online version from the CRD #71
Browse files Browse the repository at this point in the history
* variables.go
 * Adds the ImageVersion constant for population during compile

* deployment.go
 * Drops hawtioVersion as a parameter in NewDeployment and instead
   determines the version either from an env var IMAGE_VERSION, then the
   buildVariables then finally defaults to "latest"

* hawtio_types.go
 * Adds annotations to support generation of CRD

* deploy...
 * Newly generated CRD containing both v1 and v1alpha1
 * Updates CR to v1

* Makefile
 * Convenience generate rule
  • Loading branch information
phantomjinx committed Nov 28, 2023
1 parent 514bb5b commit ab9c0f9
Show file tree
Hide file tree
Showing 13 changed files with 371 additions and 29 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ manifests: controller-gen
k8s-generate: controller-gen
$(CONTROLLER_GEN) paths="./..." object

generate: k8s-generate go-generate manifests

#
# Installation of just the CRD
# Can only be executed as a cluster-admin
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion deploy/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- hawtio_v1alpha1_hawtio_crd.yaml
- hawt.io_hawtios.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: hawt.io/v1alpha1
apiVersion: hawt.io/v1
kind: Hawtio
metadata:
name: hawtio-online
Expand Down
2 changes: 1 addition & 1 deletion deploy/crs/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- hawtio_v1alpha1_hawtio_cr.yaml
- hawtio_v1_hawtio_cr.yaml
2 changes: 1 addition & 1 deletion deploy/setup/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: Kustomization
namespace: hawtio

resources:
- ../crd/hawtio_v1alpha1_hawtio_crd.yaml
- ../crd
- ../cluster_role.yaml
- ../cluster_role_binding.yaml
- ../role.yaml
Expand Down
8 changes: 4 additions & 4 deletions pkg/apis/hawtio/v1/hawtio_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,18 @@ const (
NamespaceHawtioDeploymentType HawtioDeploymentType = "Namespace"
)

// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:resource:path=hawtios,scope=Namespaced,categories=hawtio
// +kubebuilder:resource:path=hawtios,scope=Namespaced,shortName=hawt,categories=hawtio
// +kubebuilder:storageversion
// +kubebuilder:subresource:status
// +kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.selector
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`,description="Creation phase"
// +kubebuilder:printcolumn:name="Image",type=string,JSONPath=`.status.image`,description="Console image"
// +kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase`,description="Console phase"
// +kubebuilder:printcolumn:name="URL",type=string,JSONPath=`.status.URL`,description="Console URL"

// Hawtio Console
// Hawtio is the Schema for the Hawtio Console API.
type Hawtio struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand Down Expand Up @@ -70,8 +72,6 @@ type HawtioSpec struct {
Route HawtioRoute `json:"route,omitempty"`
// List of external route names that will be annotated by the operator to access the console using the routes
ExternalRoutes []string `json:"externalRoutes,omitempty"`
// The Hawtio console container image version. Defaults to 'latest'.
Version string `json:"version,omitempty"`
// The authentication configuration
Auth HawtioAuth `json:"auth,omitempty"`
// The Nginx runtime configuration
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/hawtio/hawtio_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func (r *ReconcileHawtio) Reconcile(request reconcile.Request) (reconcile.Result
}

_, err = r.reconcileDeployment(hawtio, isOpenShift4, openShiftSemVer.String(), openShiftConsoleUrl,
hawtio.Spec.Version, configMap, clientCertSecret, tlsRouteSecret, caCertRouteSecret)
configMap, clientCertSecret, tlsRouteSecret, caCertRouteSecret)
if err != nil {
reqLogger.Error(err, "Error reconciling deployment")
return reconcile.Result{}, err
Expand Down Expand Up @@ -697,13 +697,13 @@ func (r *ReconcileHawtio) reconcileConfigMap(hawtio *hawtiov1.Hawtio) (bool, err
}

func (r *ReconcileHawtio) reconcileDeployment(hawtio *hawtiov1.Hawtio,
isOpenShift4 bool, openShiftVersion, openShiftConsoleURL, hawtioVersion string,
isOpenShift4 bool, openShiftVersion string, openShiftConsoleURL string,
configMap *corev1.ConfigMap, clientCertSecret, tlsCustomSecret, caCertRouteSecret *corev1.Secret) (bool, error) {
clientCertSecretVersion := ""
if clientCertSecret != nil {
clientCertSecretVersion = clientCertSecret.GetResourceVersion()
}
deployment, err := resources.NewDeployment(hawtio, isOpenShift4, openShiftVersion, openShiftConsoleURL, hawtioVersion,
deployment, err := resources.NewDeployment(hawtio, isOpenShift4, openShiftVersion, openShiftConsoleURL,
configMap.GetResourceVersion(), clientCertSecretVersion, r.BuildVariables)
if err != nil {
return false, err
Expand Down
1 change: 0 additions & 1 deletion pkg/controller/hawtio/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ var (
},
Spec: hawtiov1.HawtioSpec{
Type: hawtiov1.NamespaceHawtioDeploymentType,
Version: "latest",
RouteHostName: "hawtio.cluster",
Config: hawtiov1.HawtioConfig{
Online: hawtiov1.HawtioOnline{
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/hawtio/test/crd_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func getCRFile(t *testing.T, dir string) string {
}

func getSchema(t *testing.T) validation.Schema {
crdFile := "../../../../deploy/crd/hawtio_v1_hawtio_crd.yaml"
crdFile := "../../../../deploy/crd/hawt.io_hawtios.yaml"
bytes, err := ioutil.ReadFile(crdFile)
assert.NoError(t, err, "Error reading CRD yaml %v", crdFile)
schema, err := validation.NewVersioned(bytes, "v1")
Expand Down
11 changes: 3 additions & 8 deletions pkg/resources/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import (

const containerPortName = "https"

func newContainer(hawtio *hawtiov1.Hawtio, envVars []corev1.EnvVar, imageRepository string) corev1.Container {
func newContainer(hawtio *hawtiov1.Hawtio, envVars []corev1.EnvVar, imageVersion string, imageRepository string) corev1.Container {
container := corev1.Container{
Name: hawtio.Name + "-container",
Image: getImageFor(hawtio.Spec.Version, imageRepository),
Image: getImageFor(imageVersion, imageRepository),
Env: envVars,
ReadinessProbe: &corev1.Probe{
InitialDelaySeconds: 5,
Expand Down Expand Up @@ -52,12 +52,7 @@ func newContainer(hawtio *hawtiov1.Hawtio, envVars []corev1.EnvVar, imageReposit
return container
}

//TODO(): will replace that function with update code committed in PR #23
func getImageFor(version string, imageRepository string) string {
tag := "latest"
if len(version) > 0 {
tag = version
}
func getImageFor(tag string, imageRepository string) string {
repository := os.Getenv("IMAGE_REPOSITORY")
if repository == "" {
if imageRepository != "" {
Expand Down
22 changes: 18 additions & 4 deletions pkg/resources/deployment.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package resources

import (
"os"
"path"

"github.com/Masterminds/semver"
Expand Down Expand Up @@ -31,8 +32,8 @@ const (
serverRootDirectory = "/usr/share/nginx/html"
)

func NewDeployment(hawtio *hawtiov1.Hawtio, isOpenShift4 bool, openShiftVersion string, openShiftConsoleURL string, hawtioVersion string, configMapVersion string, clientCertSecretVersion string, buildVariables util.BuildVariables) (*appsv1.Deployment, error) {
podTemplateSpec, err := newPodTemplateSpec(hawtio, isOpenShift4, openShiftVersion, openShiftConsoleURL, hawtioVersion, configMapVersion, clientCertSecretVersion, buildVariables)
func NewDeployment(hawtio *hawtiov1.Hawtio, isOpenShift4 bool, openShiftVersion string, openShiftConsoleURL string, configMapVersion string, clientCertSecretVersion string, buildVariables util.BuildVariables) (*appsv1.Deployment, error) {
podTemplateSpec, err := newPodTemplateSpec(hawtio, isOpenShift4, openShiftVersion, openShiftConsoleURL, configMapVersion, clientCertSecretVersion, buildVariables)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -71,8 +72,9 @@ func newDeployment(hawtio *hawtiov1.Hawtio, replicas *int32, pts corev1.PodTempl
}
}

func newPodTemplateSpec(hawtio *hawtiov1.Hawtio, isOpenShift4 bool, openShiftVersion string, openShiftConsoleURL string, hawtioVersion string, configMapVersion string, clientCertSecretVersion string, buildVariables util.BuildVariables) (corev1.PodTemplateSpec, error) {
container := newContainer(hawtio, newEnvVars(hawtio, isOpenShift4, openShiftVersion, openShiftConsoleURL), buildVariables.ImageRepository)
func newPodTemplateSpec(hawtio *hawtiov1.Hawtio, isOpenShift4 bool, openShiftVersion string, openShiftConsoleURL string, configMapVersion string, clientCertSecretVersion string, buildVariables util.BuildVariables) (corev1.PodTemplateSpec, error) {
hawtioVersion := getVersion(buildVariables)
container := newContainer(hawtio, newEnvVars(hawtio, isOpenShift4, openShiftVersion, openShiftConsoleURL), hawtioVersion, buildVariables.ImageRepository)

annotations := map[string]string{
configVersionAnnotation: configMapVersion,
Expand Down Expand Up @@ -233,3 +235,15 @@ func getServingCertificateMountPath(version string, legacyServingCertificateMoun
}
return serviceSigningSecretVolumeMountPath, nil
}

func getVersion(buildVariables util.BuildVariables) string {
version := os.Getenv("IMAGE_VERSION")
if version == "" {
if len(version) > 0 {
version = buildVariables.ImageVersion
} else {
version = "latest"
}
}
return version
}
2 changes: 2 additions & 0 deletions pkg/util/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package util
type BuildVariables struct {
// The hawtio-online operand image repository
ImageRepository string
// The hawtio-online operand image version
ImageVersion string
// Legacy serving certificate version
LegacyServingCertificateMountVersion string
// Product name
Expand Down

0 comments on commit ab9c0f9

Please sign in to comment.