Skip to content

Commit 72695e1

Browse files
authored
Merge pull request #1292 from darkweaver87/feat/logging
feat: support setting loggingService and monitoringService
2 parents f24b413 + 3e1996f commit 72695e1

File tree

5 files changed

+128
-1
lines changed

5 files changed

+128
-1
lines changed

cloud/services/container/clusters/reconcile.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,12 @@ func (s *Service) createCluster(ctx context.Context, log *logr.Logger) error {
300300
}
301301
if !s.scope.IsAutopilotCluster() {
302302
cluster.NodePools = scope.ConvertToSdkNodePools(nodePools, machinePools, isRegional, cluster.GetName())
303+
if s.scope.GCPManagedControlPlane.Spec.LoggingService != nil {
304+
cluster.LoggingService = s.scope.GCPManagedControlPlane.Spec.LoggingService.String()
305+
}
306+
if s.scope.GCPManagedControlPlane.Spec.MonitoringService != nil {
307+
cluster.MonitoringService = s.scope.GCPManagedControlPlane.Spec.MonitoringService.String()
308+
}
303309
}
304310

305311
createClusterRequest := &containerpb.CreateClusterRequest{
@@ -434,6 +440,20 @@ func (s *Service) checkDiffAndPrepareUpdate(existingCluster *containerpb.Cluster
434440
}
435441
}
436442

443+
// LoggingService
444+
if existingCluster.GetLoggingService() != s.scope.GCPManagedControlPlane.Spec.LoggingService.String() {
445+
needUpdate = true
446+
clusterUpdate.DesiredLoggingService = s.scope.GCPManagedControlPlane.Spec.LoggingService.String()
447+
log.V(2).Info("LoggingService config update required", "current", existingCluster.GetLoggingService(), "desired", s.scope.GCPManagedControlPlane.Spec.LoggingService.String())
448+
}
449+
450+
// MonitoringService
451+
if existingCluster.GetMonitoringService() != s.scope.GCPManagedControlPlane.Spec.MonitoringService.String() {
452+
needUpdate = true
453+
clusterUpdate.DesiredLoggingService = s.scope.GCPManagedControlPlane.Spec.MonitoringService.String()
454+
log.V(2).Info("MonitoringService config update required", "current", existingCluster.GetMonitoringService(), "desired", s.scope.GCPManagedControlPlane.Spec.MonitoringService.String())
455+
}
456+
437457
// DesiredMasterAuthorizedNetworksConfig
438458
// When desiredMasterAuthorizedNetworksConfig is nil, it means that the user wants to disable the feature.
439459
desiredMasterAuthorizedNetworksConfig := convertToSdkMasterAuthorizedNetworksConfig(s.scope.GCPManagedControlPlane.Spec.MasterAuthorizedNetworksConfig)

config/crd/bases/infrastructure.cluster.x-k8s.io_gcpmanagedcontrolplanes.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ spec:
165165
Location represents the location (region or zone) in which the GKE cluster
166166
will be created.
167167
type: string
168+
loggingService:
169+
description: |-
170+
LoggingService represents configuration of logging service feature of the GKE cluster.
171+
Possible values: none, logging.googleapis.com/kubernetes (default).
172+
Value is ignored when enableAutopilot = true.
173+
type: string
168174
master_authorized_networks_config:
169175
description: |-
170176
MasterAuthorizedNetworksConfig represents configuration options for master authorized networks feature of the GKE cluster.
@@ -193,6 +199,12 @@ spec:
193199
Public IP addresses.
194200
type: boolean
195201
type: object
202+
monitoringService:
203+
description: |-
204+
MonitoringService represents configuration of monitoring service feature of the GKE cluster.
205+
Possible values: none, monitoring.googleapis.com/kubernetes (default).
206+
Value is ignored when enableAutopilot = true.
207+
type: string
196208
project:
197209
description: Project is the name of the project to deploy the cluster
198210
to.

exp/api/v1beta1/gcpmanagedcontrolplane_types.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
"fmt"
21+
"strings"
22+
2023
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
"k8s.io/utils/strings/slices"
2125
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2226
)
2327

@@ -151,6 +155,16 @@ type GCPManagedControlPlaneSpec struct {
151155
// This feature is disabled if this field is not specified.
152156
// +optional
153157
MasterAuthorizedNetworksConfig *MasterAuthorizedNetworksConfig `json:"master_authorized_networks_config,omitempty"`
158+
// LoggingService represents configuration of logging service feature of the GKE cluster.
159+
// Possible values: none, logging.googleapis.com/kubernetes (default).
160+
// Value is ignored when enableAutopilot = true.
161+
// +optional
162+
LoggingService *LoggingService `json:"loggingService,omitempty"`
163+
// MonitoringService represents configuration of monitoring service feature of the GKE cluster.
164+
// Possible values: none, monitoring.googleapis.com/kubernetes (default).
165+
// Value is ignored when enableAutopilot = true.
166+
// +optional
167+
MonitoringService *MonitoringService `json:"monitoringService,omitempty"`
154168
}
155169

156170
// GCPManagedControlPlaneStatus defines the observed state of GCPManagedControlPlane.
@@ -236,6 +250,42 @@ type MasterAuthorizedNetworksConfigCidrBlock struct {
236250
CidrBlock string `json:"cidr_block,omitempty"`
237251
}
238252

253+
// LoggingService is GKE logging service configuration.
254+
type LoggingService string
255+
256+
// Validate validates LoggingService value.
257+
func (l LoggingService) Validate() error {
258+
validValues := []string{"none", "logging.googleapis.com/kubernetes"}
259+
if !slices.Contains(validValues, l.String()) {
260+
return fmt.Errorf("invalid value; expect one of : %s", strings.Join(validValues, ","))
261+
}
262+
263+
return nil
264+
}
265+
266+
// String returns a string from LoggingService.
267+
func (l LoggingService) String() string {
268+
return string(l)
269+
}
270+
271+
// MonitoringService is GKE logging service configuration.
272+
type MonitoringService string
273+
274+
// Validate validates MonitoringService value.
275+
func (m MonitoringService) Validate() error {
276+
validValues := []string{"none", "monitoring.googleapis.com/kubernetes"}
277+
if !slices.Contains(validValues, m.String()) {
278+
return fmt.Errorf("invalid value; expect one of : %s", strings.Join(validValues, ","))
279+
}
280+
281+
return nil
282+
}
283+
284+
// String returns a string from MonitoringService.
285+
func (m MonitoringService) String() string {
286+
return string(m)
287+
}
288+
239289
// GetConditions returns the control planes conditions.
240290
func (r *GCPManagedControlPlane) GetConditions() clusterv1.Conditions {
241291
return r.Status.Conditions

exp/api/v1beta1/gcpmanagedcontrolplane_webhook.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"strings"
2222

2323
"github.com/google/go-cmp/cmp"
24-
2524
apierrors "k8s.io/apimachinery/pkg/api/errors"
2625
"k8s.io/apimachinery/pkg/util/validation/field"
2726

@@ -89,6 +88,16 @@ func (r *GCPManagedControlPlane) ValidateCreate() (admission.Warnings, error) {
8988
allErrs = append(allErrs, field.Required(field.NewPath("spec", "ReleaseChannel"), "Release channel is required for an autopilot enabled cluster"))
9089
}
9190

91+
if r.Spec.EnableAutopilot && r.Spec.LoggingService != nil {
92+
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "LoggingService"),
93+
r.Spec.LoggingService, "can't be set when autopilot is enabled"))
94+
}
95+
96+
if r.Spec.EnableAutopilot && r.Spec.MonitoringService != nil {
97+
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "MonitoringService"),
98+
r.Spec.LoggingService, "can't be set when autopilot is enabled"))
99+
}
100+
92101
if len(allErrs) == 0 {
93102
return nil, nil
94103
}
@@ -130,6 +139,32 @@ func (r *GCPManagedControlPlane) ValidateUpdate(oldRaw runtime.Object) (admissio
130139
)
131140
}
132141

142+
if old.Spec.EnableAutopilot && r.Spec.LoggingService != nil {
143+
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "LoggingService"),
144+
r.Spec.LoggingService, "can't be set when autopilot is enabled"))
145+
}
146+
147+
if old.Spec.EnableAutopilot && r.Spec.MonitoringService != nil {
148+
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "MonitoringService"),
149+
r.Spec.LoggingService, "can't be set when autopilot is enabled"))
150+
}
151+
152+
if r.Spec.LoggingService != nil {
153+
err := r.Spec.LoggingService.Validate()
154+
if err != nil {
155+
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "LoggingService"),
156+
r.Spec.LoggingService, err.Error()))
157+
}
158+
}
159+
160+
if r.Spec.MonitoringService != nil {
161+
err := r.Spec.MonitoringService.Validate()
162+
if err != nil {
163+
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "MonitoringService"),
164+
r.Spec.MonitoringService, err.Error()))
165+
}
166+
}
167+
133168
if len(allErrs) == 0 {
134169
return nil, nil
135170
}

exp/api/v1beta1/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)