github.com/tigera/api@v0.0.0-20240320170621-278e89a8c5fb/pkg/apis/projectcalico/v3/uisettings.go (about)

     1  // Copyright (c) 2021 Tigera, Inc. All rights reserved.
     2  
     3  package v3
     4  
     5  import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     6  
     7  const (
     8  	KindUISettings     = "UISettings"
     9  	KindUISettingsList = "UISettingsList"
    10  )
    11  
    12  // +genclient
    13  // +genclient:nonNamespaced
    14  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    15  
    16  // UISettings contains UI settings.
    17  type UISettings struct {
    18  	metav1.TypeMeta `json:",inline"`
    19  	// Standard object's metadata.
    20  	metav1.ObjectMeta `json:"metadata,omitempty"`
    21  	// Specification of the UISettings.
    22  	Spec UISettingsSpec `json:"spec,omitempty"`
    23  }
    24  
    25  // UISettingsSpec contains the specification for a UISettings resource.
    26  type UISettingsSpec struct {
    27  	// The settings group. Once configured this cannot be modified. The group must exist.
    28  	Group string `json:"group" validate:"name"`
    29  
    30  	// This description is displayed by the UI.
    31  	Description string `json:"description" validate:"uiDescription"`
    32  
    33  	// View data. One of View, Layer or Dashboard should be specified.
    34  	View *UIGraphView `json:"view,omitempty" validate:"omitempty"`
    35  
    36  	// Layer data. One of View, Layer or Dashboard should be specified.
    37  	Layer *UIGraphLayer `json:"layer,omitempty" validate:"omitempty"`
    38  
    39  	// Dashboard data. One of View, Layer or Dashboard should be specified.
    40  	Dashboard *UIDashboard `json:"dashboard,omitempty" validate:"omitempty"`
    41  
    42  	// The user associated with these settings. This is filled in by the APIServer on a create request if the owning
    43  	// group is filtered by user. Cannot be modified.
    44  	User string `json:"user,omitempty" validate:"omitempty"`
    45  }
    46  
    47  // UIGraphView contains the data for a UI graph view.
    48  type UIGraphView struct {
    49  	// Whether ports are expanded. If false, port information is aggregated.
    50  	ExpandPorts *bool `json:"expandPorts,omitempty" validate:"omitempty"`
    51  
    52  	// Whether or not to automatically follow directly connected nodes.
    53  	FollowConnectionDirection *bool `json:"followConnectionDirection,omitempty" validate:"omitempty"`
    54  
    55  	// Whether to split HostEndpoints, NetworkSets and Networks into separate ingress and egress nodes or to combine
    56  	// them. In a service-centric view, splitting these makes the graph clearer. This never splits pods which represent
    57  	// a true microservice which has ingress and egress connections.
    58  	SplitIngressEgress *bool `json:"splitIngressEgress,omitempty" validate:"omitempty"`
    59  
    60  	// The set of selectors used to aggregate hosts (Kubernetes nodes). Nodes are aggregated based on the supplied set
    61  	// of selectors. In the case of overlapping selectors, the order specified in the slice is the order checked and so
    62  	// the first selector to match is used.  The nodes will be aggregated into a graph node with the name specified in
    63  	// the NamedSelector.
    64  	HostAggregationSelectors []NamedSelector `json:"hostAggregationSelectors,omitempty" validate:"omitempty,dive"`
    65  
    66  	// Layout type. Semi-arbitrary value used to specify the layout-type/algorithm. For example could specify
    67  	// different layout algorithms, or click-to-grid.  Mostly here for future use.
    68  	LayoutType string `json:"layoutType,omitempty" validate:"omitempty"`
    69  
    70  	// Positions of graph nodes.
    71  	Positions []Position `json:"positions,omitempty" validate:"omitempty,dive"`
    72  
    73  	// The set of layer names that are active in this view.  Note that layers may be defined, but it is not necessary
    74  	// to have each layer "active". Corresponds directly to the name of the UISettings resource that contains a layer
    75  	// definition.
    76  	Layers []string `json:"layers,omitempty" validate:"omitempty,dive,name"`
    77  
    78  	// Graph node specific view data. This provides information about what is in focus, expanded, hidden,
    79  	// deemphasized etc. at a per-node level.
    80  	Nodes []UIGraphNodeView `json:"nodes,omitempty" validate:"omitempty,dive"`
    81  }
    82  
    83  // UI screen position.
    84  type Position struct {
    85  	ID   string `json:"id" validate:"servicegraphId"`
    86  	XPos int    `json:"xPos"`
    87  	YPos int    `json:"yPos"`
    88  	ZPos int    `json:"zPos"`
    89  }
    90  
    91  // A Calico format label selector with an associated name.
    92  type NamedSelector struct {
    93  	Name     string `json:"name" validate:"uiDescription"`
    94  	Selector string `json:"selector" validate:"selector"`
    95  }
    96  
    97  // UIGraphLayer contains the data for a UI graph layer.
    98  type UIGraphLayer struct {
    99  	// The nodes that are aggregated into a single layer.
   100  	Nodes []UIGraphNode `json:"nodes" validate:"omitempty,dive"`
   101  
   102  	// A user-configurable icon. If not specified, the default layer icon is used for this layer node.
   103  	Icon string `json:"icon,omitempty" validate:"omitempty,icon"`
   104  
   105  	// The color used to represent the layer when an Icon has not been specified.
   106  	Color string `json:"color,omitempty" validate:"omitempty,color"`
   107  }
   108  
   109  // UIGraphNode contains details about a graph node so that the UI can render it correctly.
   110  type UIGraphNode struct {
   111  	// The node ID.
   112  	ID string `json:"id" validate:"servicegraphId"`
   113  
   114  	// The node type.
   115  	Type string `json:"type" validate:"servicegraphNodeType"`
   116  
   117  	// The node name.
   118  	Name string `json:"name" validate:"serviceGraphNodeName"`
   119  
   120  	// The node namespace.
   121  	Namespace string `json:"namespace,omitempty" validate:"omitempty,serviceGraphNodeName"`
   122  }
   123  
   124  // UIGraphNodeView contains the view configuration for a specific graph node.
   125  type UIGraphNodeView struct {
   126  	UIGraphNode `json:",inline"`
   127  
   128  	// This node is a primary focus of the graph (i.e. the graph contains this node and connected nodes).
   129  	InFocus *bool `json:"inFocus,omitempty" validate:"omitempty"`
   130  
   131  	// This node is expanded to the next level.  This node can, for example, be a layer that is expanded into its
   132  	// constituent parts.
   133  	Expanded *bool `json:"expanded,omitempty" validate:"omitempty"`
   134  
   135  	// Whether the ingress/egress connections to/from this node are included in the graph.  This effectively brings
   136  	// more nodes into focus.
   137  	FollowIngress *bool `json:"followIngress,omitempty" validate:"omitempty"`
   138  	FollowEgress  *bool `json:"followEgress,omitempty" validate:"omitempty"`
   139  
   140  	// Whether the UI should de-emphasize the node when visible. This is just a UI directive and does not correspond to
   141  	// a backend parameter.
   142  	Deemphasize *bool `json:"deemphasize,omitempty" validate:"omitempty"`
   143  
   144  	// Whether the UI should hide the node. This is just a UI directive and does not correspond to a backend parameter.
   145  	Hide *bool `json:"hide,omitempty" validate:"omitempty"`
   146  
   147  	// Whether the UI should hide unrelated nodes. This is just a UI directive and does not correspond to a backend
   148  	// parameter.
   149  	HideUnrelated *bool `json:"hideUnrelated,omitempty" validate:"omitempty"`
   150  }
   151  
   152  // UIDashboard contains the data for a UI dashboard.
   153  type UIDashboard struct {
   154  	// Array of dashboard data
   155  	DashboardData []DashboardData `json:"dashboardData,omitempty" validate:"omitempty"`
   156  }
   157  
   158  type DashboardData struct {
   159  	// Namespace user selected for the dashboard
   160  	SelectedNamespace string `json:"selectedNamespace,omitempty" validate:"omitempty"`
   161  
   162  	// Type of the dashboard
   163  	Type string `json:"type,omitempty" validate:"omitempty"`
   164  
   165  	// Layout information of the dashboard card
   166  	Layout DashboardLayout `json:"layout,omitempty" validate:"omitempty"`
   167  }
   168  
   169  type DashboardLayout struct {
   170  	// Index of the dashboard
   171  	Index *string `json:"index,omitempty" validate:"omitempty"`
   172  
   173  	// X coordinate of the top-left corner of the dashboard card
   174  	XPos uint32 `json:"xPos"`
   175  	// Y coordinate of the top-left corner of the dashboard card
   176  	YPos uint32 `json:"yPos"`
   177  
   178  	// Width of the dashboard card
   179  	Width uint32 `json:"width" validate:"gt=0"`
   180  	// Height of the dashboard card
   181  	Height uint32 `json:"height" validate:"gt=0"`
   182  
   183  	// Minimum limit set for the size of the dashboard card width
   184  	MinWidth *uint32 `json:"minWidth,omitempty" validate:"omitempty,gt=0"`
   185  	// Maximum limit set for the size of the dashboard card width
   186  	MaxWidth *uint32 `json:"maxWidth,omitempty" validate:"omitempty,gt=0"`
   187  
   188  	// Minimum limit set for the size of the dashboard card height
   189  	MinHeight *uint32 `json:"minHeight,omitempty" validate:"omitempty,gt=0"`
   190  	// Maximum limit set for the size of the dashboard card height
   191  	MaxHeight *uint32 `json:"maxHeight,omitempty" validate:"omitempty,gt=0"`
   192  
   193  	// Whether this dashboard card should be re-sizeable or not
   194  	IsResizable *bool `json:"isResizable,omitempty" validate:"omitempty"`
   195  
   196  	// Whether this dashboard card should be visible or not
   197  	IsVisible *bool `json:"isVisible,omitempty" validate:"omitempty"`
   198  
   199  	// Whether this dashboard is in namespace view or not
   200  	IsInNamespaceView *bool `json:"isInNamespaceView,omitempty" validate:"omitempty"`
   201  }
   202  
   203  // +genclient:nonNamespaced
   204  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
   205  
   206  // UISettingsList contains a list of UISettings resources.
   207  type UISettingsList struct {
   208  	metav1.TypeMeta `json:",inline"`
   209  	metav1.ListMeta `json:"metadata"`
   210  	Items           []UISettings `json:"items"`
   211  }
   212  
   213  // NewUISettings creates a new (zeroed) UISettings struct with the TypeMetadata
   214  // initialised to the current version.
   215  func NewUISettings() *UISettings {
   216  	return &UISettings{
   217  		TypeMeta: metav1.TypeMeta{
   218  			Kind:       KindUISettings,
   219  			APIVersion: GroupVersionCurrent,
   220  		},
   221  	}
   222  }
   223  
   224  // NewUISettingsList creates a new (zeroed) UISettingsList struct with the
   225  // TypeMetadata initialised to the current version.
   226  func NewUISettingsList() *UISettingsList {
   227  	return &UISettingsList{
   228  		TypeMeta: metav1.TypeMeta{
   229  			Kind:       KindUISettingsList,
   230  			APIVersion: GroupVersionCurrent,
   231  		},
   232  	}
   233  }