Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 25 additions & 36 deletions cmd/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (

corev1 "k8s.io/api/core/v1"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/sets"
Expand Down Expand Up @@ -1459,7 +1458,7 @@ func (c *config) clusterDelete(args []string) error {

genericcli.Must(c.listPrinter.Print(resp.Payload))

firstPartOfClusterID := strings.Split(*resp.Payload.ID, "-")[0]
firstPartOfClusterID, _, _ := strings.Cut(*resp.Payload.ID, "-")
fmt.Println("Please answer some security questions to delete this cluster")
err = helper.Prompt("first part of clusterID:", firstPartOfClusterID)
if err != nil {
Expand Down Expand Up @@ -1675,35 +1674,29 @@ func (c *config) clusterDNSManifest(args []string) error {
switch t := viper.GetString("type"); t {
case "ingress":
ingress := &networkingv1.Ingress{
TypeMeta: metav1.TypeMeta{
Kind: "Ingress",
APIVersion: networkingv1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: viper.GetString("name"),
Namespace: viper.GetString("namespace"),
Labels: map[string]string{
"app": viper.GetString("name"),
},
Annotations: annotations,
Kind: "Ingress",
APIVersion: networkingv1.SchemeGroupVersion.String(),
Name: viper.GetString("name"),
Namespace: viper.GetString("namespace"),
Labels: map[string]string{
"app": viper.GetString("name"),
},
Annotations: annotations,
Spec: networkingv1.IngressSpec{
IngressClassName: new(viper.GetString("ingress-class")),
Rules: []networkingv1.IngressRule{
{
Host: domain,
IngressRuleValue: networkingv1.IngressRuleValue{
HTTP: &networkingv1.HTTPIngressRuleValue{
Paths: []networkingv1.HTTPIngressPath{
{
PathType: new(networkingv1.PathTypePrefix),
Path: "/",
Backend: networkingv1.IngressBackend{
Service: &networkingv1.IngressServiceBackend{
Name: viper.GetString("backend-name"),
Port: networkingv1.ServiceBackendPort{
Number: viper.GetInt32("backend-port"),
},
HTTP: &networkingv1.HTTPIngressRuleValue{
Paths: []networkingv1.HTTPIngressPath{
{
PathType: new(networkingv1.PathTypePrefix),
Path: "/",
Backend: networkingv1.IngressBackend{
Service: &networkingv1.IngressServiceBackend{
Name: viper.GetString("backend-name"),
Port: networkingv1.ServiceBackendPort{
Number: viper.GetInt32("backend-port"),
},
},
},
Expand All @@ -1727,18 +1720,14 @@ func (c *config) clusterDNSManifest(args []string) error {
resource = ingress
case "service":
service := &corev1.Service{
TypeMeta: metav1.TypeMeta{
Kind: "Service",
APIVersion: corev1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: viper.GetString("name"),
Namespace: viper.GetString("namespace"),
Labels: map[string]string{
"app": viper.GetString("name"),
},
Annotations: annotations,
Kind: "Service",
APIVersion: corev1.SchemeGroupVersion.String(),
Name: viper.GetString("name"),
Namespace: viper.GetString("namespace"),
Labels: map[string]string{
"app": viper.GetString("name"),
},
Annotations: annotations,
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeLoadBalancer,
Selector: map[string]string{
Expand Down
6 changes: 2 additions & 4 deletions cmd/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,7 @@ func (d *dashboard) Render() {

healthResp, err := d.cloud.Health.Health(health.NewHealthParams().WithContext(ctx), nil)
if err != nil {
var r *health.HealthInternalServerError
if errors.As(err, &r) {
if r, ok := errors.AsType[*health.HealthInternalServerError](err); ok {
healthResp = health.NewHealthOK()
healthResp.Payload = r.Payload
} else {
Expand Down Expand Up @@ -1100,8 +1099,7 @@ func (d *dashboardVolumePane) Render() error {

clusters, err = d.cache.VolumeClusterInfo(ctx)
if err != nil {
var typedErr *volume.ClusterInfoDefault
if errors.As(err, &typedErr) {
if typedErr, ok := errors.AsType[*volume.ClusterInfoDefault](err); ok {
if typedErr.Code() != http.StatusForbidden {
return err
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ func newHealthCmd(c *config) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
resp, err := c.cloud.Health.Health(nil, nil)
if err != nil {
var r *health.HealthInternalServerError
if errors.As(err, &r) {
if r, ok := errors.AsType[*health.HealthInternalServerError](err); ok {
resp = health.NewHealthOK()
resp.Payload = r.Payload
} else {
Expand Down
18 changes: 9 additions & 9 deletions cmd/output/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/metal-stack/metal-lib/pkg/pointer"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8syaml "sigs.k8s.io/yaml"
)

Expand Down Expand Up @@ -235,8 +234,10 @@ func VolumeManifest(v models.V1VolumeResponse, name, namespace, sc string) error

filesystem := corev1.PersistentVolumeFilesystem
pv := corev1.PersistentVolume{
TypeMeta: v1.TypeMeta{Kind: "PersistentVolume", APIVersion: "v1"},
ObjectMeta: v1.ObjectMeta{Name: name, Namespace: namespace},
Kind: "PersistentVolume",
APIVersion: corev1.SchemeGroupVersion.Version,
Name: name,
Namespace: namespace,
Spec: corev1.PersistentVolumeSpec{
AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
VolumeMode: &filesystem,
Expand Down Expand Up @@ -268,12 +269,11 @@ func VolumeManifest(v models.V1VolumeResponse, name, namespace, sc string) error

func VolumeEncryptionSecretManifest(namespace, passphrase string) error {
secret := corev1.Secret{
TypeMeta: v1.TypeMeta{Kind: "Secret", APIVersion: "v1"},
ObjectMeta: v1.ObjectMeta{
Name: "storage-encryption-key",
Namespace: namespace,
},
Type: corev1.SecretTypeOpaque,
Kind: "Secret",
APIVersion: corev1.SchemeGroupVersion.Version,
Name: "storage-encryption-key",
Namespace: namespace,
Type: corev1.SecretTypeOpaque,
StringData: map[string]string{
"host-encryption-passphrase": passphrase,
},
Expand Down
3 changes: 1 addition & 2 deletions cmd/project-reservations.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ func (m machineReservationsCmd) Create(rq *models.V1MachineReservationCreateRequ
WithBody(rq).
WithForce(new(viper.GetBool("force"))), nil)
if err != nil {
var r *project.CreateMachineReservationConflict
if errors.As(err, &r) {
if _, ok := errors.AsType[*project.CreateMachineReservationConflict](err); ok {
return nil, genericcli.AlreadyExistsError()
}
return nil, err
Expand Down
Loading