|
| 1 | +/* |
| 2 | +Copyright 2021 RedHatInsights. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1alpha1 |
| 18 | + |
| 19 | +import ( |
| 20 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | +) |
| 22 | + |
| 23 | +type BundlePermissionArgs []string |
| 24 | + |
| 25 | +type BundlePermission struct { |
| 26 | + Method string `json:"method"` |
| 27 | + Args []BundlePermissionArgs `json:"args"` |
| 28 | +} |
| 29 | + |
| 30 | +type BundleNavItem struct { |
| 31 | + Title string `json:"title"` |
| 32 | + GroupID string `json:"groupId,omitempty"` |
| 33 | + NavItems []LeafBundleNavItem `json:"navItems,omitempty"` |
| 34 | + AppId string `json:"appId,omitempty"` |
| 35 | + Href string `json:"href,omitempty"` |
| 36 | + Product string `json:"product,omitempty"` |
| 37 | + IsExternal bool `json:"isExternal,omitempty"` |
| 38 | + Filterable bool `json:"filterable,omitempty"` |
| 39 | + Permissions []BundlePermission `json:"permissions,omitempty"` |
| 40 | + Routes []LeafBundleNavItem `json:"routes,omitempty"` |
| 41 | +} |
| 42 | + |
| 43 | +type LeafBundleNavItem struct { |
| 44 | + Title string `json:"title"` |
| 45 | + GroupID string `json:"groupId,omitempty"` |
| 46 | + AppId string `json:"appId,omitempty"` |
| 47 | + Href string `json:"href,omitempty"` |
| 48 | + Product string `json:"product,omitempty"` |
| 49 | + IsExternal bool `json:"isExternal,omitempty"` |
| 50 | + Filterable bool `json:"filterable,omitempty"` |
| 51 | + Permissions []BundlePermission `json:"permissions,omitempty"` |
| 52 | +} |
| 53 | + |
| 54 | +type ComputedBundle struct { |
| 55 | + ID string `json:"id"` |
| 56 | + Title string `json:"title"` |
| 57 | + NavItems []BundleNavItem `json:"navItems"` |
| 58 | +} |
| 59 | + |
| 60 | +type ExtraNavItem struct { |
| 61 | + Name string `json:"name"` |
| 62 | + NavItem BundleNavItem `json:"navItem"` |
| 63 | +} |
| 64 | + |
| 65 | +// BundleSpec defines the desired state of Bundle |
| 66 | +type BundleSpec struct { |
| 67 | + // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster |
| 68 | + // Important: Run "make" to regenerate code after modifying this file |
| 69 | + |
| 70 | + // Foo is an example field of Bundle. Edit Bundle_types.go to remove/update |
| 71 | + ID string `json:"id"` |
| 72 | + Title string `json:"title"` |
| 73 | + AppList []string `json:"appList"` |
| 74 | + EnvName string `json:"envName"` |
| 75 | + ExtraNavItems []ExtraNavItem `json:"extraNavItems,omitempty"` |
| 76 | +} |
| 77 | + |
| 78 | +// BundleStatus defines the observed state of Bundle |
| 79 | +type BundleStatus struct { |
| 80 | + // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster |
| 81 | + // Important: Run "make" to regenerate code after modifying this file |
| 82 | +} |
| 83 | + |
| 84 | +//+kubebuilder:object:root=true |
| 85 | +//+kubebuilder:subresource:status |
| 86 | + |
| 87 | +// Bundle is the Schema for the Bundles API |
| 88 | +type Bundle struct { |
| 89 | + metav1.TypeMeta `json:",inline"` |
| 90 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 91 | + |
| 92 | + Spec BundleSpec `json:"spec,omitempty"` |
| 93 | + Status BundleStatus `json:"status,omitempty"` |
| 94 | +} |
| 95 | + |
| 96 | +//+kubebuilder:object:root=true |
| 97 | + |
| 98 | +// BundleList contains a list of Bundle |
| 99 | +type BundleList struct { |
| 100 | + metav1.TypeMeta `json:",inline"` |
| 101 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 102 | + Items []Bundle `json:"items"` |
| 103 | +} |
| 104 | + |
| 105 | +func init() { |
| 106 | + SchemeBuilder.Register(&Bundle{}, &BundleList{}) |
| 107 | +} |
| 108 | + |
| 109 | +// GetLabels returns a base set of labels relating to the ClowdApp. |
| 110 | +func (i *Bundle) GetLabels() map[string]string { |
| 111 | + if i.Labels == nil { |
| 112 | + i.Labels = map[string]string{} |
| 113 | + } |
| 114 | + |
| 115 | + if _, ok := i.Labels["Bundle"]; !ok { |
| 116 | + i.Labels["Bundle"] = i.ObjectMeta.Name |
| 117 | + } |
| 118 | + |
| 119 | + newMap := make(map[string]string, len(i.Labels)) |
| 120 | + |
| 121 | + for k, v := range i.Labels { |
| 122 | + newMap[k] = v |
| 123 | + } |
| 124 | + |
| 125 | + return newMap |
| 126 | +} |
0 commit comments