Skip to content

Commit 988d218

Browse files
committed
added webhook for oidc feature and corrected conversion
corrected image path
1 parent 14a4958 commit 988d218

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

api/v1beta1/ocimanagedcontrolplane_conversion.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,26 @@ func (src *OCIManagedControlPlane) ConvertTo(dstRaw conversion.Hub) error {
3636
dst.Spec.ClusterType = restored.Spec.ClusterType
3737
dst.Spec.Addons = restored.Spec.Addons
3838
dst.Status.AddonStatus = restored.Status.AddonStatus
39-
dst.Spec.ClusterOption.OpenIdConnectDiscovery.IsOpenIdConnectDiscoveryEnabled = restored.Spec.ClusterOption.OpenIdConnectDiscovery.IsOpenIdConnectDiscoveryEnabled
39+
40+
// Handle ClusterOption conversion
41+
// Copy OpenIdConnectDiscovery if present
42+
if restored.Spec.ClusterOption.OpenIdConnectDiscovery != nil {
43+
if dst.Spec.ClusterOption.OpenIdConnectDiscovery == nil {
44+
dst.Spec.ClusterOption.OpenIdConnectDiscovery = &v1beta2.OpenIDConnectDiscovery{}
45+
}
46+
dst.Spec.ClusterOption.OpenIdConnectDiscovery.IsOpenIdConnectDiscoveryEnabled =
47+
restored.Spec.ClusterOption.OpenIdConnectDiscovery.IsOpenIdConnectDiscoveryEnabled
48+
}
49+
50+
// Copy OpenIdConnectTokenAuthenticationConfig if present
51+
if restored.Spec.ClusterOption.OpenIdConnectTokenAuthenticationConfig != nil {
52+
if dst.Spec.ClusterOption.OpenIdConnectTokenAuthenticationConfig == nil {
53+
dst.Spec.ClusterOption.OpenIdConnectTokenAuthenticationConfig = &v1beta2.OpenIDConnectTokenAuthenticationConfig{}
54+
}
55+
*dst.Spec.ClusterOption.OpenIdConnectTokenAuthenticationConfig =
56+
*restored.Spec.ClusterOption.OpenIdConnectTokenAuthenticationConfig
57+
}
58+
4059
return nil
4160
}
4261

api/v1beta2/ocimanagedcontrolplane_webhook.go

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

1919
import (
20+
"github.com/oracle/oci-go-sdk/v65/common"
2021
apierrors "k8s.io/apimachinery/pkg/api/errors"
2122
"k8s.io/apimachinery/pkg/runtime"
2223
"k8s.io/apimachinery/pkg/util/validation/field"
@@ -56,6 +57,18 @@ func (c *OCIManagedControlPlane) ValidateCreate() (admission.Warnings, error) {
5657
if len(c.Name) > 31 {
5758
allErrs = append(allErrs, field.Invalid(field.NewPath("Name"), c.Name, "Name cannot be more than 31 characters"))
5859
}
60+
61+
if c.Spec.ClusterOption.OpenIdConnectTokenAuthenticationConfig.IsOpenIdConnectAuthEnabled == *common.Bool(true) {
62+
if c.Spec.ClusterType != EnhancedClusterType {
63+
allErrs = append(allErrs, field.Invalid(field.NewPath("ClusterType"), c.Spec.ClusterType, "ClusterType needs to be set to ENHANCED_CLUSTER for OpenIdConnectTokenAuthenticationConfig to be enabled."))
64+
}
65+
if c.Spec.ClusterOption.OpenIdConnectTokenAuthenticationConfig.ClientId == nil {
66+
allErrs = append(allErrs, field.Invalid(field.NewPath("ClientId"), c.Spec.ClusterOption.OpenIdConnectTokenAuthenticationConfig.ClientId, "ClientId cannot be empty when OpenIdConnectAuth is enabled."))
67+
}
68+
if c.Spec.ClusterOption.OpenIdConnectTokenAuthenticationConfig.IssuerUrl == nil {
69+
allErrs = append(allErrs, field.Invalid(field.NewPath("IssuerUrl "), c.Spec.ClusterOption.OpenIdConnectTokenAuthenticationConfig.IssuerUrl, "IssuerUrl cannot be empty when OpenIdConnectAuth is enabled."))
70+
}
71+
}
5972
if len(allErrs) == 0 {
6073
return nil, nil
6174
}

config/default/manager_image_patch.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ spec:
88
spec:
99
containers:
1010
# Change the value of image field below to your controller image URL
11-
- image: tsmini/cluster-api-oci-controller-amd64:dev
11+
- image: ghcr.io/oracle/cluster-api-oci-controller-amd64:dev
1212
name: manager

0 commit comments

Comments
 (0)