Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions pkg/controller/operconfig/operconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

appsv1 "k8s.io/api/apps/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
uns "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -50,10 +51,10 @@ func newReconciler(mgr manager.Manager, status *statusmanager.StatusManager) *Re
configv1.Install(mgr.GetScheme())
operv1.Install(mgr.GetScheme())
return &ReconcileOperConfig{
client: mgr.GetClient(),
scheme: mgr.GetScheme(),
status: status,

client: mgr.GetClient(),
scheme: mgr.GetScheme(),
status: status,
mapper: mgr.GetRESTMapper(),
podReconciler: newPodReconciler(status),
}
}
Expand Down Expand Up @@ -95,10 +96,10 @@ var _ reconcile.Reconciler = &ReconcileOperConfig{}
type ReconcileOperConfig struct {
// This client, initialized using mgr.Client() above, is a split client
// that reads objects from the cache and writes to the apiserver
client client.Client
scheme *runtime.Scheme
status *statusmanager.StatusManager

client client.Client
scheme *runtime.Scheme
status *statusmanager.StatusManager
mapper meta.RESTMapper
podReconciler *ReconcilePods
}

Expand Down Expand Up @@ -208,15 +209,28 @@ func (r *ReconcileOperConfig) Reconcile(request reconcile.Request) (reconcile.Re
// Set up the Pod reconciler before we start creating DaemonSets/Deployments
daemonSets := []types.NamespacedName{}
deployments := []types.NamespacedName{}
relatedObjects := []configv1.ObjectReference{}
for _, obj := range objs {
if obj.GetAPIVersion() == "apps/v1" && obj.GetKind() == "DaemonSet" {
daemonSets = append(daemonSets, types.NamespacedName{Namespace: obj.GetNamespace(), Name: obj.GetName()})
} else if obj.GetAPIVersion() == "apps/v1" && obj.GetKind() == "Deployment" {
deployments = append(deployments, types.NamespacedName{Namespace: obj.GetNamespace(), Name: obj.GetName()})
}
restMapping, err := r.mapper.RESTMapping(obj.GroupVersionKind().GroupKind())
if err != nil {
log.Printf("Failed to get REST mapping for storing related object: %v", err)
continue
}
relatedObjects = append(relatedObjects, configv1.ObjectReference{
Group: obj.GetObjectKind().GroupVersionKind().Group,
Resource: restMapping.Resource.Resource,
Name: obj.GetName(),
Namespace: obj.GetNamespace(),
})
}
r.status.SetDaemonSets(daemonSets)
r.status.SetDeployments(deployments)
r.status.SetRelatedObjects(relatedObjects)

allResources := []types.NamespacedName{}
allResources = append(allResources, daemonSets...)
Expand Down
10 changes: 8 additions & 2 deletions pkg/controller/statusmanager/status_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ type StatusManager struct {

failing [maxStatusLevel]*configv1.ClusterOperatorStatusCondition

daemonSets []types.NamespacedName
deployments []types.NamespacedName
daemonSets []types.NamespacedName
deployments []types.NamespacedName
relatedObjects []configv1.ObjectReference
}

func New(client client.Client, name, version string) *StatusManager {
Expand All @@ -57,6 +58,7 @@ func (status *StatusManager) Set(reachedAvailableLevel bool, conditions ...confi
}

oldStatus := co.Status.DeepCopy()
co.Status.RelatedObjects = status.relatedObjects

if reachedAvailableLevel {
if releaseVersion := os.Getenv("RELEASE_VERSION"); len(releaseVersion) > 0 {
Expand Down Expand Up @@ -155,6 +157,10 @@ func (status *StatusManager) SetDeployments(deployments []types.NamespacedName)
status.deployments = deployments
}

func (status *StatusManager) SetRelatedObjects(relatedObjects []configv1.ObjectReference) {
status.relatedObjects = relatedObjects
}

// SetFromPods sets the operator Degraded/Progressing/Available status, based on
// the current status of the manager's DaemonSets and Deployments.
func (status *StatusManager) SetFromPods() {
Expand Down