Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ClusterAPI v1alpha1 → v1alpha2 / k8s_meetup_23

Ryo Takaishi
September 27, 2019

ClusterAPI v1alpha1 → v1alpha2 / k8s_meetup_23

Ryo Takaishi

September 27, 2019
Tweet

More Decks by Ryo Takaishi

Other Decks in Technology

Transcript

  1. !6 ઃఆʹैͬͯ5BSHFU$MVTUFSΛ࡞੒ DMVTUFSDUM #PPUTUSBQ$MVTUFS 5BSHFU$MVTUFS DMVTUFSBQJNBOBHFS ֤छ$POpH.BQ w ֤छϦιʔεΛ࡞੒ w

    $POUSPM1MBOF༻ͷΠϯελϯε w 4FDVSJUZ(SPVQ w ωοτϫʔΫͳͲ w LVCFBENͰΫϥελʔߏங w طଘΫϥελʔΛར༻ w LVCFBEN WJSUVBMCPYͰखݩʹߏங
  2. ˙ W͔Β"1*͕WBMQIBʹมߋ ˙ ΞʔΩςΫνϟ͕͔ͳΓมΘͬͨ ˙ ͭͷϚωʔδϟʔʢίϯτϩʔϥʔʣͰߏ੒͞ΕΔ w $PSF $MVTUFS"1* 

    w #PPUTUSBQ LVCFBEN  w *OGSBTUSVDUVSF BXT PQFOTUBDL EPDLFS FUDʜ !9 $MVTUFS"1*WBMQIB WBMQIBͰ͸ϓϩόΠμʔຖʹϚωʔδϟ͕ ͭ͋ΔͷΈͩͬͨ
  3. ˙ $MVTUFS w ίΞ෦෼ ˙ #PPUTUSBQ w LVCFBENΛ࢖͏ίʔυΛݮΒ͢͜ͱ͕໨త w WBMQIBͰ͸શϓϩόΠμʔ͕࣮૷

    w $MPVE*OJUͷσʔλੜ੒ͳͲΛߦ͏ ˙ *OGSBTUSVDUVSF w WBMQIBͰ͍͏ϓϩόΠμʔɻ w Ϋϥ΢υͳͲΠϯϑϥݸผͷϩδοΫΛड͚࣋ͭ !10 ෼ׂͷૂ͍ IUUQTDMVTUFSBQJTJHTLTJPQSPWJEFSTWBMQIBUPWBMQIBIUNM
  4. ˙ DMVTUFSBQJ w $MVTUFS3FDPODJMFS w .BDIJOF3FDPODJMFS w .BDIJOF4FU3FDPODJMFS w .BDIJOF%FQMPZNFOU3FDPODJMFS

    ˙ DMVTUFSBQJCPPUTUSBQQSPWJEFSLVCFBEN w ,VCFBEN$POpH3FDPODJMFS ˙ DMVTUFSBQJQSPWJEFSBXT w "84$MVTUFS3FDPODJMFS w "84.BDIJOF3FDPODJMFS !11 ͦΕͧΕ͕࣋ͭ3FDPODJMFS
  5. !14 --- apiVersion: cluster.x-k8s.io/v1alpha2 kind: Cluster metadata: name: ${CLUSTER_NAME} spec:

    clusterNetwork: pods: cidrBlocks: ["192.168.0.0/16"] infrastructureRef: apiVersion: infrastructure.cluster.x-k8s.io/ v1alpha2 kind: AWSCluster name: ${CLUSTER_NAME} Cluster / AWSClusterΛݟͯΈΔ IUUQTHJUIVCDPNLVCFSOFUFTTJHTDMVTUFSBQJQSPWJEFSBXTCMPCWFYBNQMFTDMVTUFSDMVTUFSZBNM --- apiVersion: infrastructure.cluster.x- k8s.io/v1alpha2 kind: AWSCluster metadata: name: ${CLUSTER_NAME} spec: region: ${AWS_REGION} sshKeyName: ${SSH_KEY_NAME} LJOE$MVTUFS LJOE"84$MVTUFS ࡞੒͢ΔΫϥελͷ *OGSBTUSVDUVSF৘ใΛࢀর
  6. !15 // ClusterSpec defines the desired state of Cluster type

    ClusterSpec struct { // Cluster network configuration // +optional ClusterNetwork *ClusterNetwork `json:"clusterNetwork,omitempty"` // InfrastructureRef is a reference to a provider-specific resource that holds the details // for provisioning infrastructure for a cluster in said provider. // +optional InfrastructureRef *corev1.ObjectReference `json:"infrastructureRef,omitempty"` InfrastructureRefͱ͸Կͳͷ͔ IUUQTHJUIVCDPNLVCFSOFUFTTJHTDMVTUFSBQJCMPCWBQJWBMQIBDMVTUFS@UZQFTHP
  7. !16 type ObjectReference struct { Kind string `json:"kind,omitempty" protobuf:"bytes,1,opt,name=kind"` Namespace

    string `json:"namespace,omitempty" protobuf:"bytes,2,opt,name=namespace"` Name string `json:"name,omitempty" protobuf:"bytes,3,opt,name=name"` UID types.UID `json:"uid,omitempty" protobuf:"bytes,4,opt,name=uid,casttype=k8s.io/ apimachinery/pkg/types.UID"` APIVersion string `json:"apiVersion,omitempty" protobuf:"bytes,5,opt,name=apiVersion"` ResourceVersion string `json:"resourceVersion,omitempty" protobuf:"bytes, 6,opt,name=resourceVersion"` FieldPath string `json:"fieldPath,omitempty" protobuf:”bytes,7,opt,name=fieldPath"` } corev1.ObjectReference IUUQTHJUIVCDPNLVCFSOFUFTBQJCMPCLVCFSOFUFTDPSFWUZQFTHP
  8. !17 // reconcileInfrastructure reconciles the Spec.InfrastructureRef object on a Cluster.

    func (r *ClusterReconciler) reconcileInfrastructure(ctx context.Context, cluster *v1alpha2.Cluster) error { if cluster.Spec.InfrastructureRef == nil { return nil } // Call generic external reconciler. infraConfig, err := r.reconcileExternal(ctx, cluster, cluster.Spec.InfrastructureRef) Ͳ͏࢖ΘΕ͍ͯΔͷ͔ IUUQTHJUIVCDPNLVCFSOFUFTTJHTDMVTUFSBQJCMPCWDPOUSPMMFSTDMVTUFS@DPOUSPMMFS@QIBTFTHP // reconcileExternal handles generic unstructured objects referenced by a Cluster. func (r *ClusterReconciler) reconcileExternal(ctx context.Context, cluster *v1alpha2.Cluster, ref *corev1.ObjectReference) (*unstructured.Unstructured, error) { obj, err := external.Get(r.Client, ref, cluster.Namespace) if err != nil { if apierrors.IsNotFound(err) { return nil, errors.Wrapf(&capierrors.RequeueAfterError{RequeueAfter: 30 * time.Second}, "could not find %v %q for Cluster %q in namespace %q, requeuing",
  9. !18 // Get uses the client and reference to get

    an external, unstructured object. func Get(c client.Client, ref *corev1.ObjectReference, namespace string) (*unstructured.Unstructured, error) { obj := new(unstructured.Unstructured) obj.SetAPIVersion(ref.APIVersion) obj.SetKind(ref.Kind) obj.SetName(ref.Name) key := client.ObjectKey{Name: obj.GetName(), Namespace: namespace} if err := c.Get(context.Background(), key, obj); err != nil { return nil, err } return obj, nil } corev1.ObjectReference IUUQTHJUIVCDPNLVCFSOFUFTTJHTDMVTUFSBQJCMPCWDPOUSPMMFSTFYUFSOBMVUJMHP
  10. !19 // Event is a report of an event somewhere

    in the cluster. type Event struct { metav1.TypeMeta `json:",inline"` // Standard object's metadata. // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata metav1.ObjectMeta `json:"metadata" protobuf:"bytes,1,opt,name=metadata"` // The object that this event is about. InvolvedObject ObjectReference `json:"involvedObject" protobuf:"bytes,2,opt,name=involvedObject"` ࢀߟɿObjectReference͸EventϦιʔεͰ΋࢖ΘΕ͍ͯΔ IUUQTHJUIVCDPNLVCFSOFUFTTJHTDMVTUFSBQJCMPCWDPOUSPMMFSTFYUFSOBMVUJMHP