Skip to content

Commit

Permalink
add upgrade insights controller/crd
Browse files Browse the repository at this point in the history
  • Loading branch information
floreks committed Sep 9, 2024
1 parent c98827a commit e79aba9
Show file tree
Hide file tree
Showing 14 changed files with 882 additions and 11 deletions.
117 changes: 117 additions & 0 deletions api/v1alpha1/upgradeinsights_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package v1alpha1

import (
"time"

console "github.com/pluralsh/console/go/client"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func init() {
SchemeBuilder.Register(&UpgradeInsights{}, &UpgradeInsightsList{})
}

const (
defaultReconcileInterval = 10 * time.Minute
)

// UpgradeInsightsList contains a list of UpgradeInsights
// +kubebuilder:object:root=true
type UpgradeInsightsList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []UpgradeInsights `json:"items"`
}

// UpgradeInsights is the Schema for the UpgradeInsights API
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="ID",type="string",JSONPath=".status.id",description="ID of the UpgradeInsights in the Console API."
type UpgradeInsights struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec UpgradeInsightsSpec `json:"spec,omitempty"`
Status Status `json:"status,omitempty"`
}

func (in *UpgradeInsights) SetCondition(condition metav1.Condition) {
meta.SetStatusCondition(&in.Status.Conditions, condition)
}

type UpgradeInsightsDistro string

type UpgradeInsightsSpec struct {
// Distro defines which provider API should be used to fetch latest upgrade insights.
// If not provided, we get the distro from the Plural API cluster tied to this operator deploy token.
// +kubebuilder:validation:Enum=EKS
// +kubebuilder:validation:Optional
Distro *console.ClusterDistro `json:"distro,omitempty"`

// ClusterName is your cloud provider cluster identifier (usually name) that is used
// to fetch latest upgrade insights information from the cloud provider API.
// If not provided, we get the cluster name from the Plural API cluster tied to this
// operator deploy token and assume that it is the same as the cluster name in your cloud provider.
// +kubebuilder:validation:Optional
ClusterName *string `json:"clusterName,omitempty"`

// Interval defines how often should the upgrade insights information be fetched.
// +kubebuilder:default="10m"
// +kubebuilder:validation:Optional
Interval *string `json:"interval,omitempty"`

// Credentials allow overriding default provider credentials bound to the operator.
// +kubebuilder:validation:Optional
Credentials *ProviderCredentials `json:"credentials,omitempty"`
}

func (in *UpgradeInsightsSpec) GetDistro(defaultDistro *console.ClusterDistro) *console.ClusterDistro {
if in.Distro != nil {
return in.Distro
}

return defaultDistro
}
func (in *UpgradeInsightsSpec) GetClusterName(defaultClusterName string) string {
if in.ClusterName != nil {
return *in.ClusterName
}

return defaultClusterName
}

func (in *UpgradeInsightsSpec) GetInterval() time.Duration {
if in.Interval == nil {
return defaultReconcileInterval
}

interval, err := time.ParseDuration(*in.Interval)
if err != nil {
return defaultReconcileInterval
}

return interval
}

type ProviderCredentials struct {
// AWS defines attributes required to auth with AWS API.
// +kubebuilder:validation:Optional
AWS *AWSProviderCredentials `json:"aws,omitempty"`
}

type AWSProviderCredentials struct {
// Region ...
// +kubebuilder:validation:Required
Region string `json:"region"`

// AccessKeyID ...
// +kubebuilder:validation:Required
AccessKeyID string `json:"accessKeyID"`

// SecretAccessKeyRef ...
// +kubebuilder:validation:Required
SecretAccessKeyRef corev1.SecretReference `json:"secretAccessKeyRef"`
}
130 changes: 130 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ func main() {
setupLog.Error(err, "unable to create controller", "controller", "VirtualCluster")
}

if err = (&controller.UpgradeInsightsController{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
ConsoleClient: ctrlMgr.GetClient(),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "UpgradeInsights")
}

statusController, err := controller.NewStatusReconciler(mgr.GetClient())
if err != nil {
setupLog.Error(err, "unable to create controller", "controller", "StatusController")
Expand Down
Loading

0 comments on commit e79aba9

Please sign in to comment.