Skip to content

Commit

Permalink
Add appsub status reference to subcription CRD
Browse files Browse the repository at this point in the history
Signed-off-by: Philip Wu <[email protected]>
  • Loading branch information
philipwu08 committed Mar 21, 2022
1 parent 0106601 commit 0c1db99
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.6.0
creationTimestamp: null
name: subscriptions.apps.open-cluster-management.io
spec:
group: apps.open-cluster-management.io
Expand All @@ -14,9 +19,13 @@ 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
Expand Down Expand Up @@ -47,10 +56,34 @@ spec:
spec:
description: SubscriptionSpec defines the desired state of Subscription
properties:
allow:
items:
description: AllowDenyItem is a group resources allowed or denied
for deployment
properties:
apiVersion:
type: string
kinds:
items:
type: string
type: array
type: object
type: array
channel:
type: string
secondaryChannel:
type: string
deny:
items:
description: AllowDenyItem is a group resources allowed or denied
for deployment
properties:
apiVersion:
type: string
kinds:
items:
type: string
type: array
type: object
type: array
hooksecretref:
description: 'ObjectReference contains enough information to let you
inspect or modify the referred object. --- New uses of this type
Expand Down Expand Up @@ -123,8 +156,8 @@ spec:
type: string
clusterOverrides:
items:
description: ClusterOverride describes rules for override
type: object
x-kubernetes-preserve-unknown-fields: true
minItems: 1
type: array
required:
Expand Down Expand Up @@ -211,45 +244,13 @@ spec:
type: string
packageOverrides:
items:
description: PackageOverride describes rules for override
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
required:
- packageName
type: object
type: array
allow:
description: To allow deployment of listed resources
items:
description: Set of kubernetes group resources allowed to be deployed
properties:
apiVersion:
type: string
kinds:
items:
type: string
type: array
required:
- apiVersion
- kinds
type: object
type: array
deny:
description: To deny deployment of listed resources
items:
description: Set of kubernetes group resources not allowed to be deployed
properties:
apiVersion:
type: string
kinds:
items:
type: string
type: array
required:
- apiVersion
- kinds
type: object
type: array
placement:
description: For hub use only, to specify which clusters to go to
properties:
Expand Down Expand Up @@ -373,6 +374,10 @@ spec:
type: string
type: object
type: object
secondaryChannel:
description: When fails to connect to the channel, connect to the
secondary channel
type: string
timewindow:
description: help user control when the subscription will take affect
properties:
Expand Down Expand Up @@ -436,6 +441,8 @@ spec:
type: string
type: array
type: object
appstatusReference:
type: string
lastUpdateTime:
format: date-time
type: string
Expand Down Expand Up @@ -471,7 +478,6 @@ spec:
type: string
resourceStatus:
type: object
x-kubernetes-preserve-unknown-fields: true
required:
- lastUpdateTime
type: object
Expand All @@ -488,3 +494,9 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
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
11 changes: 11 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,16 @@ func (r *ReconcileSubscription) Reconcile(ctx context.Context, request reconcile
klog.Errorf("doReconcile got error %v", reconcileErr)
}

// Update AppstatusReference
if !r.standalone {
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

0 comments on commit 0c1db99

Please sign in to comment.