Skip to content

Commit 4e6886c

Browse files
authored
Merge pull request #11 from moelsayed/managed_metrics
feat: Migrate managed and federated types
2 parents 43e1972 + f8ab679 commit 4e6886c

34 files changed

+532
-1170
lines changed

api/v1alpha1/common_types.go

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
package v1alpha1
22

3-
import "k8s.io/apimachinery/pkg/runtime/schema"
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
"k8s.io/apimachinery/pkg/runtime/schema"
6+
)
7+
8+
const (
9+
// StatusTrue indicates the metric resource is considered ready/active.
10+
StatusTrue = "True"
11+
// StatusFalse indicates the metric resource is not ready/active.
12+
StatusFalse = "False"
13+
)
414

515
// GroupVersionKind defines the group, version and kind of the object that should be instrumented
616
type GroupVersionKind struct {
@@ -19,3 +29,39 @@ func (gvk *GroupVersionKind) GVK() schema.GroupVersionKind {
1929
Version: gvk.Version,
2030
}
2131
}
32+
33+
// Projection defines the projection of the metric
34+
type Projection struct {
35+
// Define the name of the field that should be extracted
36+
Name string `json:"name,omitempty"`
37+
38+
// Define the path to the field that should be extracted
39+
FieldPath string `json:"fieldPath,omitempty"`
40+
}
41+
42+
// Dimension defines the dimension of the metric
43+
type Dimension struct {
44+
Name string `json:"name,omitempty"`
45+
Value string `json:"value,omitempty"`
46+
}
47+
48+
// MetricObservation represents the latest available observation of an object's state
49+
type MetricObservation struct {
50+
// The timestamp of the observation
51+
Timestamp metav1.Time `json:"timestamp,omitempty"`
52+
53+
// The latest value of the metric
54+
LatestValue string `json:"latestValue,omitempty"`
55+
56+
Dimensions []Dimension `json:"dimensions,omitempty"`
57+
}
58+
59+
// GetTimestamp returns the timestamp of the observation
60+
func (mo *MetricObservation) GetTimestamp() metav1.Time {
61+
return mo.Timestamp
62+
}
63+
64+
// GetValue returns the latest value of the metric
65+
func (mo *MetricObservation) GetValue() string {
66+
return mo.LatestValue
67+
}

api/v1beta1/federatedclusteraccess_types.go renamed to api/v1alpha1/federatedclusteraccess_types.go

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,22 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package v1beta1
17+
package v1alpha1
1818

1919
import (
20-
"strings"
21-
2220
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2321
)
2422

25-
// FederateCAFacade defines the desired state of FederatedClusterAccess
26-
type FederateCAFacade struct {
27-
FederatedCARef FederateCARef `json:"federateCaRef,omitempty"`
28-
}
29-
30-
// FederateCARef is a reference to a FederateCA
31-
type FederateCARef struct {
23+
// FederateClusterAccessRef is a reference to a FederateCA
24+
type FederateClusterAccessRef struct {
3225
Name string `json:"name,omitempty"`
3326
Namespace string `json:"namespace,omitempty"`
3427
}
3528

3629
// FederatedClusterAccessSpec defines the desired state of FederatedClusterAccess
3730
type FederatedClusterAccessSpec struct {
3831
// Define the target resources that should be monitored
39-
Target GroupVersionResource `json:"target,omitempty"`
32+
Target GroupVersionKind `json:"target,omitempty"`
4033

4134
// Field that contains the kubeconfig to access the target cluster. Use dot notation to access nested fields.
4235
KubeConfigPath string `json:"kubeConfigPath,omitempty"`
@@ -45,17 +38,6 @@ type FederatedClusterAccessSpec struct {
4538

4639
}
4740

48-
// GroupVersionResource defines the target resource
49-
type GroupVersionResource struct {
50-
Group string `json:"group,omitempty"`
51-
Version string `json:"version,omitempty"`
52-
Resource string `json:"resource,omitempty"`
53-
}
54-
55-
func (gvr *GroupVersionResource) String() string {
56-
return strings.Join([]string{gvr.Group, "/", gvr.Version, ", Resource=", gvr.Resource}, "")
57-
}
58-
5941
// FederatedClusterAccessStatus defines the observed state of FederatedClusterAccess
6042
type FederatedClusterAccessStatus struct {
6143
}
@@ -84,24 +66,3 @@ type FederatedClusterAccessList struct {
8466
func init() {
8567
SchemeBuilder.Register(&FederatedClusterAccess{}, &FederatedClusterAccessList{})
8668
}
87-
88-
// MetricObservation stores the last observation details
89-
type MetricObservation struct {
90-
// The timestamp of the observation
91-
Timestamp metav1.Time `json:"timestamp,omitempty"`
92-
93-
// The latest value of the metric
94-
LatestValue string `json:"latestValue,omitempty"`
95-
96-
Dimensions []Dimension `json:"dimensions,omitempty"`
97-
}
98-
99-
// GetTimestamp returns the timestamp of the observation
100-
func (mo *MetricObservation) GetTimestamp() metav1.Time {
101-
return mo.Timestamp
102-
}
103-
104-
// GetValue returns the latest value of the metric
105-
func (mo *MetricObservation) GetValue() string {
106-
return mo.LatestValue
107-
}

api/v1beta1/federatedmanagedmetric_types.go renamed to api/v1alpha1/federatedmanagedmetric_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package v1beta1
17+
package v1alpha1
1818

1919
import (
2020
"k8s.io/apimachinery/pkg/api/meta"
@@ -41,7 +41,7 @@ type FederatedManagedMetricSpec struct {
4141
// +kubebuilder:default:="12h"
4242
CheckInterval metav1.Duration `json:"checkInterval,omitempty"`
4343

44-
FederateCAFacade `json:",inline"`
44+
FederatedClusterAccessRef FederateClusterAccessRef `json:"federateClusterAccessRef,omitempty"`
4545
}
4646

4747
// FederatedManagedMetricStatus defines the observed state of FederatedManagedMetric
Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package v1beta1
17+
package v1alpha1
1818

1919
import (
2020
"k8s.io/apimachinery/pkg/api/meta"
@@ -29,7 +29,7 @@ type FederatedMetricSpec struct {
2929
Description string `json:"description,omitempty"`
3030

3131
// +kubebuilder:validation:Required
32-
Target GroupVersionResource `json:"target,omitempty"`
32+
Target GroupVersionKind `json:"target,omitempty"`
3333

3434
// Define labels of your object to adapt filters of the query
3535
// +optional
@@ -44,22 +44,7 @@ type FederatedMetricSpec struct {
4444
// +kubebuilder:default:="12h"
4545
CheckInterval metav1.Duration `json:"checkInterval,omitempty"`
4646

47-
FederateCAFacade `json:",inline"`
48-
}
49-
50-
// Projection defines the projection of the metric
51-
type Projection struct {
52-
// Define the name of the field that should be extracted
53-
Name string `json:"name,omitempty"`
54-
55-
// Define the path to the field that should be extracted
56-
FieldPath string `json:"fieldPath,omitempty"`
57-
}
58-
59-
// Dimension defines the dimension of the metric
60-
type Dimension struct {
61-
Name string `json:"name,omitempty"`
62-
Value string `json:"value,omitempty"`
47+
FederatedClusterAccessRef FederateClusterAccessRef `json:"federateClusterAccessRef,omitempty"`
6348
}
6449

6550
// FederatedObservation represents the latest available observation of an object's state

api/v1alpha1/managedmetric_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type ManagedMetricSpec struct {
4646
// +kubebuilder:default:="12h"
4747
CheckInterval metav1.Duration `json:"checkInterval,omitempty"`
4848

49-
RemoteClusterAccessFacade `json:",inline"`
49+
RemoteClusterAccessRef `json:"remoteClusterAccessRef,omitempty"`
5050
}
5151

5252
// ManagedObservation represents the latest available observation of an object's state

api/v1alpha1/metric_types.go

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,6 @@ const (
3636
PhasePending PhaseType = "Pending"
3737
)
3838

39-
// Projection defines the projection of the metric
40-
type Projection struct {
41-
// Define the name of the field that should be extracted
42-
Name string `json:"name,omitempty"`
43-
44-
// Define the path to the field that should be extracted
45-
FieldPath string `json:"fieldPath,omitempty"`
46-
}
47-
48-
// Dimension defines the dimension of the metric
49-
type Dimension struct {
50-
Name string `json:"name,omitempty"`
51-
Value string `json:"value,omitempty"`
52-
}
53-
5439
// MetricSpec defines the desired state of Metric
5540
type MetricSpec struct {
5641
// Sets the name that will be used to identify the metric in Dynatrace(or other providers)
@@ -70,32 +55,11 @@ type MetricSpec struct {
7055
// +kubebuilder:default:="12h"
7156
CheckInterval metav1.Duration `json:"checkInterval,omitempty"`
7257

73-
RemoteClusterAccessFacade `json:",inline"`
58+
RemoteClusterAccessRef `json:"remoteClusterAccessRef,omitempty"`
7459

7560
Projections []Projection `json:"projections,omitempty"`
7661
}
7762

78-
// MetricObservation represents the latest available observation of an object's state
79-
type MetricObservation struct {
80-
// The timestamp of the observation
81-
Timestamp metav1.Time `json:"timestamp,omitempty"`
82-
83-
// The latest value of the metric
84-
LatestValue string `json:"latestValue,omitempty"`
85-
86-
Dimensions []Dimension `json:"dimensions,omitempty"`
87-
}
88-
89-
// GetTimestamp returns the timestamp of the observation
90-
func (mo *MetricObservation) GetTimestamp() metav1.Time {
91-
return mo.Timestamp
92-
}
93-
94-
// GetValue returns the latest value of the metric
95-
func (mo *MetricObservation) GetValue() string {
96-
return mo.LatestValue
97-
}
98-
9963
// MetricStatus defines the observed state of ManagedMetric
10064
type MetricStatus struct {
10165

api/v1alpha1/remoteclusteraccess_types.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2121
)
2222

23-
// RemoteClusterAccessFacade is a facade to reference a RemoteClusterAccess type
24-
type RemoteClusterAccessFacade struct {
25-
// Reference to the RemoteClusterAccess type that either reference a kubeconfig or a service account and cluster secret for remote access
26-
// +optional
27-
RemoteClusterAccessRef *RemoteClusterAccessRef `json:"remoteClusterAccessRef,omitempty"`
28-
}
29-
3023
// RemoteClusterAccessRef is to be used by other types to reference a RemoteClusterAccess type
3124
type RemoteClusterAccessRef struct {
3225
Name string `json:"name,omitempty"`

0 commit comments

Comments
 (0)