Skip to content

Commit

Permalink
add watch logic for addondeploymentconfig
Browse files Browse the repository at this point in the history
Signed-off-by: Coleen Iona Quadros <[email protected]>
  • Loading branch information
coleenquadros committed Dec 5, 2023
1 parent 4d9d8fd commit 69642f7
Show file tree
Hide file tree
Showing 16 changed files with 561 additions and 30 deletions.
2 changes: 1 addition & 1 deletion COMPONENT_VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.9.0
2.10.0
5 changes: 4 additions & 1 deletion REMEDIATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,7 @@

### Thu Apr 6 23:33:50 EDT 2023

### Wed Oct 11 01:29:03 EDT 2023
### Wed Oct 11 01:29:03 EDT 2023

### Wed Nov 29 23:59:40 EST 2023
- Rebuild for 2.10 branch
61 changes: 61 additions & 0 deletions collectors/metrics/Containerfile.operator
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright Contributors to the Open Cluster Management project
# Licensed under the Apache License 2.0

FROM brew.registry.redhat.io/rh-osbs/openshift-golang-builder:rhel_8_1.20 AS builder

WORKDIR /workspace
COPY go.sum go.mod ./
COPY ./collectors/metrics ./collectors/metrics
COPY ./operators/pkg ./operators/pkg
COPY ./operators/multiclusterobservability/api ./operators/multiclusterobservability/api
RUN CGO_ENABLED=1 go build -a -installsuffix cgo -v -o metrics-collector ./collectors/metrics/cmd/metrics-collector/main.go

FROM registry.access.redhat.com/ubi8/ubi-minimal:latest

ARG VCS_REF
ARG VCS_URL
ARG IMAGE_NAME
ARG IMAGE_DESCRIPTION
ARG IMAGE_DISPLAY_NAME
ARG IMAGE_NAME_ARCH
ARG IMAGE_MAINTAINER
ARG IMAGE_VENDOR
ARG IMAGE_VERSION
ARG IMAGE_RELEASE
ARG IMAGE_SUMMARY
ARG IMAGE_OPENSHIFT_TAGS

LABEL org.label-schema.vendor="Red Hat" \
org.label-schema.name="$IMAGE_NAME_ARCH" \
org.label-schema.description="$IMAGE_DESCRIPTION" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url=$VCS_URL \
org.label-schema.license="Red Hat Advanced Cluster Management for Kubernetes EULA" \
org.label-schema.schema-version="1.0" \
name="$IMAGE_NAME" \
maintainer="$IMAGE_MAINTAINER" \
vendor="$IMAGE_VENDOR" \
version="$IMAGE_VERSION" \
release="$IMAGE_RELEASE" \
description="$IMAGE_DESCRIPTION" \
summary="$IMAGE_SUMMARY" \
io.k8s.display-name="$IMAGE_DISPLAY_NAME" \
io.k8s.description="$IMAGE_DESCRIPTION" \
io.openshift.tags="$IMAGE_OPENSHIFT_TAGS"

RUN microdnf update &&\
microdnf install ca-certificates vi --nodocs &&\
mkdir /licenses &&\
microdnf clean all

USER 1001:1001

COPY --from=builder /workspace/metrics-collector /usr/bin/

# standalone required parameters
ENV FROM_CA_FILE="/from/service-ca.crt"
ENV INTERVAL="60s"
ENV MATCH_FILE="/metrics/match-file"
ENV LIMIT_BYTES=1073741824

CMD ["/bin/bash", "-c", "/usr/bin/metrics-collector --from ${FROM} --from-ca-file ${FROM_CA_FILE} --from-token ${FROM_TOKEN} --to-upload ${TO_UPLOAD} --id ${TENANT_ID} --label cluster=${CLUSTER_NAME} --label clusterID=${CLUSTER_ID} --match-file ${MATCH_FILE} --interval ${INTERVAL} --limit-bytes=${LIMIT_BYTES}"]
55 changes: 55 additions & 0 deletions loaders/dashboards/Containerfile.operator
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright Contributors to the Open Cluster Management project
# Licensed under the Apache License 2.0

FROM brew.registry.redhat.io/rh-osbs/openshift-golang-builder:rhel_8_1.20 AS builder

WORKDIR /workspace
COPY go.sum go.mod ./loaders/dashboards ./
COPY ./loaders/dashboards ./loaders/dashboards

RUN CGO_ENABLED=1 go build -a -installsuffix cgo -v -o main loaders/dashboards/cmd/main.go

FROM registry.access.redhat.com/ubi8/ubi-minimal:latest

ARG VCS_REF
ARG VCS_URL
ARG IMAGE_NAME
ARG IMAGE_DESCRIPTION
ARG IMAGE_DISPLAY_NAME
ARG IMAGE_NAME_ARCH
ARG IMAGE_MAINTAINER
ARG IMAGE_VENDOR
ARG IMAGE_VERSION
ARG IMAGE_RELEASE
ARG IMAGE_SUMMARY
ARG IMAGE_OPENSHIFT_TAGS

LABEL org.label-schema.vendor="Red Hat" \
org.label-schema.name="$IMAGE_NAME_ARCH" \
org.label-schema.description="$IMAGE_DESCRIPTION" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url=$VCS_URL \
org.label-schema.license="Red Hat Advanced Cluster Management for Kubernetes EULA" \
org.label-schema.schema-version="1.0" \
name="$IMAGE_NAME" \
maintainer="$IMAGE_MAINTAINER" \
vendor="$IMAGE_VENDOR" \
version="$IMAGE_VERSION" \
release="$IMAGE_RELEASE" \
description="$IMAGE_DESCRIPTION" \
summary="$IMAGE_SUMMARY" \
io.k8s.display-name="$IMAGE_DISPLAY_NAME" \
io.k8s.description="$IMAGE_DESCRIPTION" \
io.openshift.tags="$IMAGE_OPENSHIFT_TAGS"

WORKDIR /

RUN microdnf update -y && microdnf clean all

USER 1001:1001

COPY --from=builder /workspace/main grafana-dashboard-loader

EXPOSE 3002

ENTRYPOINT ["/grafana-dashboard-loader"]
58 changes: 58 additions & 0 deletions operators/endpointmetrics/Containerfile.operator
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright (c) 2021 Red Hat, Inc.
# Copyright Contributors to the Open Cluster Management project.
FROM brew.registry.redhat.io/rh-osbs/openshift-golang-builder:rhel_8_1.20 AS builder

WORKDIR /workspace
COPY go.sum go.mod ./
COPY ./operators/endpointmetrics ./operators/endpointmetrics
COPY ./operators/multiclusterobservability/api ./operators/multiclusterobservability/api
COPY ./operators/pkg ./operators/pkg

RUN CGO_ENABLED=1 go build -a -installsuffix cgo -o build/_output/bin/endpoint-monitoring-operator operators/endpointmetrics/main.go

FROM registry.access.redhat.com/ubi8/ubi-minimal:latest

ARG VCS_REF
ARG VCS_URL
ARG IMAGE_NAME
ARG IMAGE_DESCRIPTION
ARG IMAGE_DISPLAY_NAME
ARG IMAGE_NAME_ARCH
ARG IMAGE_MAINTAINER
ARG IMAGE_VENDOR
ARG IMAGE_VERSION
ARG IMAGE_RELEASE
ARG IMAGE_SUMMARY
ARG IMAGE_OPENSHIFT_TAGS

LABEL org.label-schema.vendor="Red Hat" \
org.label-schema.name="$IMAGE_NAME_ARCH" \
org.label-schema.description="$IMAGE_DESCRIPTION" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url=$VCS_URL \
org.label-schema.license="Red Hat Advanced Cluster Management for Kubernetes EULA" \
org.label-schema.schema-version="1.0" \
name="$IMAGE_NAME" \
maintainer="$IMAGE_MAINTAINER" \
vendor="$IMAGE_VENDOR" \
version="$IMAGE_VERSION" \
release="$IMAGE_RELEASE" \
description="$IMAGE_DESCRIPTION" \
summary="$IMAGE_SUMMARY" \
io.k8s.display-name="$IMAGE_DISPLAY_NAME" \
io.k8s.description="$IMAGE_DESCRIPTION" \
io.openshift.tags="$IMAGE_OPENSHIFT_TAGS"

ENV OPERATOR=/usr/local/bin/endpoint-monitoring-operator \
USER_UID=1001 \
USER_NAME=endpoint-monitoring-operator

RUN microdnf update -y && microdnf clean all

COPY ./operators/endpointmetrics/manifests /usr/local/manifests

# install operator binary
COPY --from=builder /workspace/build/_output/bin/endpoint-monitoring-operator ${OPERATOR}
USER ${USER_UID}

ENTRYPOINT ["/usr/local/bin/endpoint-monitoring-operator"]
62 changes: 62 additions & 0 deletions operators/multiclusterobservability/Containerfile.operator
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright Contributors to the Open Cluster Management project
# Licensed under the Apache License 2.0

FROM brew.registry.redhat.io/rh-osbs/openshift-golang-builder:rhel_8_1.20 AS builder

WORKDIR /workspace
COPY go.sum go.mod ./
COPY ./operators/multiclusterobservability ./operators/multiclusterobservability
COPY ./operators/pkg ./operators/pkg

RUN CGO_ENABLED=1 go build -a -installsuffix cgo -o bin/manager operators/multiclusterobservability/main.go

FROM registry.access.redhat.com/ubi8/ubi-minimal:latest

ARG VCS_REF
ARG VCS_URL
ARG IMAGE_NAME
ARG IMAGE_DESCRIPTION
ARG IMAGE_DISPLAY_NAME
ARG IMAGE_NAME_ARCH
ARG IMAGE_MAINTAINER
ARG IMAGE_VENDOR
ARG IMAGE_VERSION
ARG IMAGE_RELEASE
ARG IMAGE_SUMMARY
ARG IMAGE_OPENSHIFT_TAGS

LABEL org.label-schema.vendor="Red Hat" \
org.label-schema.name="$IMAGE_NAME_ARCH" \
org.label-schema.description="$IMAGE_DESCRIPTION" \
org.label-schema.vcs-ref=$VCS_REF \
org.label-schema.vcs-url=$VCS_URL \
org.label-schema.license="Red Hat Advanced Cluster Management for Kubernetes EULA" \
org.label-schema.schema-version="1.0" \
name="$IMAGE_NAME" \
maintainer="$IMAGE_MAINTAINER" \
vendor="$IMAGE_VENDOR" \
version="$IMAGE_VERSION" \
release="$IMAGE_RELEASE" \
description="$IMAGE_DESCRIPTION" \
summary="$IMAGE_SUMMARY" \
io.k8s.display-name="$IMAGE_DISPLAY_NAME" \
io.k8s.description="$IMAGE_DESCRIPTION" \
io.openshift.tags="$IMAGE_OPENSHIFT_TAGS"

ENV OPERATOR=/usr/local/bin/mco-operator \
USER_UID=1001 \
USER_NAME=mco

RUN microdnf update -y && microdnf clean all

# install templates
COPY ./operators/multiclusterobservability/manifests /usr/local/manifests

# install the prestop script
COPY ./operators/multiclusterobservability/prestop.sh /usr/local/bin/prestop.sh

# install operator binary
COPY --from=builder /workspace/bin/manager ${OPERATOR}
USER ${USER_UID}

ENTRYPOINT ["/usr/local/bin/mco-operator"]
Original file line number Diff line number Diff line change
Expand Up @@ -325,31 +325,6 @@ func createManifestWorks(
}
}

// If ProxyConfig is specified as part of addonConfig, set the proxy envs
if clusterName != localClusterName {
for i := range spec.Containers {
container := &spec.Containers[i]
if addonConfig.Spec.ProxyConfig.HTTPProxy != "" {
container.Env = append(container.Env, corev1.EnvVar{
Name: "HTTP_PROXY",
Value: addonConfig.Spec.ProxyConfig.HTTPProxy,
})
}
if addonConfig.Spec.ProxyConfig.HTTPSProxy != "" {
container.Env = append(container.Env, corev1.EnvVar{
Name: "HTTPS_PROXY",
Value: addonConfig.Spec.ProxyConfig.HTTPSProxy,
})
}
if addonConfig.Spec.ProxyConfig.NoProxy != "" {
container.Env = append(container.Env, corev1.EnvVar{
Name: "NO_PROXY",
Value: addonConfig.Spec.ProxyConfig.NoProxy,
})
}
}
}

if hasCustomRegistry {
oldImage := container.Image
newImage, err := imageRegistryClient.Cluster(clusterName).ImageOverride(oldImage)
Expand All @@ -360,6 +335,32 @@ func createManifestWorks(
}
}
}
for i := range spec.Containers {
if spec.Containers[i].Name == "endpoint-observability-operator" {
container := &spec.Containers[i]

if clusterName != localClusterName {
if addonConfig.Spec.ProxyConfig.HTTPProxy != "" {
container.Env = append(container.Env, corev1.EnvVar{
Name: "HTTP_PROXY",
Value: addonConfig.Spec.ProxyConfig.HTTPProxy,
})
}
if addonConfig.Spec.ProxyConfig.HTTPSProxy != "" {
container.Env = append(container.Env, corev1.EnvVar{
Name: "HTTPS_PROXY",
Value: addonConfig.Spec.ProxyConfig.HTTPSProxy,
})
}
if addonConfig.Spec.ProxyConfig.NoProxy != "" {
container.Env = append(container.Env, corev1.EnvVar{
Name: "NO_PROXY",
Value: addonConfig.Spec.ProxyConfig.NoProxy,
})
}
}
}
}
log.Info(fmt.Sprintf("Cluster: %+v, Spec.NodeSelector (after): %+v", clusterName, spec.NodeSelector))
log.Info(fmt.Sprintf("Cluster: %+v, Spec.Tolerations (after): %+v", clusterName, spec.Tolerations))
dep.Spec.Template.Spec = spec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,34 @@ func (r *PlacementRuleReconciler) SetupWithManager(mgr ctrl.Manager) error {

clusterPred := getClusterPreds()

// Watch changes for AddonDeploymentConfig
AddonDeploymentPred := predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool {
//if e.Object.GetName() == defaultAddonDeploymentConfig.Name &&
// e.Object.GetNamespace() == defaultAddonDeploymentConfig.Namespace {
// log.Info("default AddonDeploymentConfig is created")
// return true
//}
return true
},
UpdateFunc: func(e event.UpdateEvent) bool {
if e.ObjectNew.GetName() == defaultAddonDeploymentConfig.Name &&
e.ObjectNew.GetNamespace() == defaultAddonDeploymentConfig.Namespace {
log.Info("default AddonDeploymentConfig is updated")
return true
}
return false
},
DeleteFunc: func(e event.DeleteEvent) bool {
if e.Object.GetName() == defaultAddonDeploymentConfig.Name &&
e.Object.GetNamespace() == defaultAddonDeploymentConfig.Namespace {
log.Info("default AddonDeploymentConfig is deleted")
return true
}
return false
},
}

obsAddonPred := predicate.Funcs{
CreateFunc: func(e event.CreateEvent) bool {
return false
Expand Down Expand Up @@ -829,6 +857,20 @@ func (r *PlacementRuleReconciler) SetupWithManager(mgr ctrl.Manager) error {
// secondary watch for alertmanager accessor serviceaccount
Watches(&source.Kind{Type: &corev1.ServiceAccount{}}, &handler.EnqueueRequestForObject{}, builder.WithPredicates(amAccessorSAPred))

// watch for AddonDeploymentConfig
if _, err := r.RESTMapper.RESTMapping(schema.GroupKind{Group: addonv1alpha1.GroupVersion.Group, Kind: "AddOnDeploymentConfig"}, addonv1alpha1.GroupVersion.Version); err == nil {
ctrBuilder = ctrBuilder.Watches(
&source.Kind{Type: &addonv1alpha1.AddOnDeploymentConfig{}},
handler.EnqueueRequestsFromMapFunc(func(obj client.Object) []reconcile.Request {
return []reconcile.Request{
{NamespacedName: types.NamespacedName{
Name: config.AddonDeploymentConfigUpdateName,
}},
}
}),
builder.WithPredicates(AddonDeploymentPred),
)
}
manifestWorkGroupKind := schema.GroupKind{Group: workv1.GroupVersion.Group, Kind: "ManifestWork"}
if _, err := r.RESTMapper.RESTMapping(manifestWorkGroupKind, workv1.GroupVersion.Version); err == nil {
workPred := getManifestworkPred()
Expand Down Expand Up @@ -937,7 +979,8 @@ func StartPlacementController(mgr manager.Manager, crdMap map[string]bool) error
func isReconcileRequired(request ctrl.Request, managedCluster string) bool {
if request.Name == config.MCOUpdatedRequestName ||
request.Name == config.MCHUpdatedRequestName ||
request.Name == config.ClusterManagementAddOnUpdateName {
request.Name == config.ClusterManagementAddOnUpdateName ||
request.Name == config.AddonDeploymentConfigUpdateName {
return true
}
if request.Namespace == config.GetDefaultNamespace() ||
Expand Down
Loading

0 comments on commit 69642f7

Please sign in to comment.