Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add appsub status reference to subcription CRD #133

Merged
merged 2 commits into from
Mar 23, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ metadata:
spec:
additionalPrinterColumns:
- JSONPath: .status.phase
description: subscription status
name: Status
description: subscription state
name: SubscriptionState
type: string
- JSONPath: .status.appstatusReference
description: subscription status reference
name: AppstatusReference
type: string
- JSONPath: .metadata.creationTimestamp
name: Age
type: date
Expand Down Expand Up @@ -416,6 +420,8 @@ spec:
type: string
type: array
type: object
appstatusReference:
type: string
lastUpdateTime:
format: date-time
type: string
Expand Down Expand Up @@ -484,10 +490,14 @@ spec:
scope: Namespaced
versions:
- additionalPrinterColumns:
- description: subscription status
- description: subscription state
jsonPath: .status.phase
name: Status
name: SubscriptionState
type: string
- description: subscription status reference
jsonPath: .status.appstatusReference
name: AppstatusReference
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
Expand Down Expand Up @@ -906,6 +916,8 @@ spec:
type: string
type: array
type: object
appstatusReference:
type: string
lastUpdateTime:
format: date-time
type: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ spec:
scope: Namespaced
versions:
- additionalPrinterColumns:
- description: subscription status
- description: subscription state
jsonPath: .status.phase
name: Status
name: SubscriptionState
type: string
- description: subscription status reference
jsonPath: .status.appstatusReference
name: AppstatusReference
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
Expand Down Expand Up @@ -436,6 +440,8 @@ spec:
type: string
type: array
type: object
appstatusReference:
type: string
lastUpdateTime:
format: date-time
type: string
Expand Down Expand Up @@ -487,4 +493,4 @@ spec:
served: true
storage: true
subresources:
status: {}
status: {}
14 changes: 8 additions & 6 deletions pkg/apis/apps/v1/subscription_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ type ClusterOverrides struct {
type SubscriptionSpec struct {
Channel string `json:"channel"`
// When fails to connect to the channel, connect to the secondary channel
SecondaryChannel string `json:"secondaryChannel"`
SecondaryChannel string `json:"secondaryChannel,omitempty"`
// To specify 1 package in channel
Package string `json:"name,omitempty"`
// To specify more than 1 package in channel
Expand Down Expand Up @@ -263,10 +263,11 @@ type AnsibleJobsStatus struct {
type SubscriptionStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Phase SubscriptionPhase `json:"phase,omitempty"`
Message string `json:"message,omitempty"`
Reason string `json:"reason,omitempty"`
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
Phase SubscriptionPhase `json:"phase,omitempty"`
AppstatusReference string `json:"appstatusReference,omitempty"`
Message string `json:"message,omitempty"`
Reason string `json:"reason,omitempty"`
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`

// +optional
AnsibleJobsStatus AnsibleJobsStatus `json:"ansiblejobs,omitempty"`
Expand All @@ -281,7 +282,8 @@ type SubscriptionStatus struct {
// Subscription is the Schema for the subscriptions API
// +k8s:openapi-gen=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.phase",description="subscription status"
// +kubebuilder:printcolumn:name="SubscriptionState",type="string",JSONPath=".status.phase",description="subscription state"
// +kubebuilder:printcolumn:name="AppstatusReference",type="string",JSONPath=".status.appstatusReference",description="subscription status reference"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:printcolumn:name="Local placement",type="boolean",JSONPath=".spec.placement.local"
// +kubebuilder:printcolumn:name="Time window",type="string",JSONPath=".spec.timewindow.windowtype"
Expand Down
9 changes: 9 additions & 0 deletions pkg/controller/subscription/subscription_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package subscription

import (
"context"
"fmt"
"strings"
"time"

Expand Down Expand Up @@ -250,6 +251,14 @@ func (r *ReconcileSubscription) Reconcile(ctx context.Context, request reconcile
klog.Errorf("doReconcile got error %v", reconcileErr)
}

// Update AppstatusReference
appsubStatusName := request.NamespacedName.Name
if strings.HasSuffix(appsubStatusName, "-local") {
appsubStatusName = appsubStatusName[:len(appsubStatusName)-6]
}

instance.Status.AppstatusReference = fmt.Sprintf("kubectl get appsubstatus -n %s %s", request.NamespacedName.Namespace, appsubStatusName)

// if the subscription pause lable is true, stop updating subscription status.
if subutil.GetPauseLabel(instance) {
klog.Info("updating subscription status: ", request.NamespacedName, " is paused")
Expand Down
2 changes: 1 addition & 1 deletion pkg/synchronizer/kubernetes/sync_appsubstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (sync *KubeSynchronizer) SyncAppsubClusterStatus(appsub *appv1.Subscription
appsubName := appsubClusterStatus.AppSub.Name
pkgstatusNs := appsubClusterStatus.AppSub.Namespace

if isLocalCluster {
if isLocalCluster || sync.standalone && skipOrphanDel {
if strings.HasSuffix(appsubName, "-local") {
appsubName = appsubName[:len(appsubName)-6]
}
Expand Down